Skip to content

pgwire,hba: introduce the 'trust' and 'reject' auth methods#43731

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20200106-hba-rules
Jan 8, 2020
Merged

pgwire,hba: introduce the 'trust' and 'reject' auth methods#43731
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20200106-hba-rules

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Jan 6, 2020

First commits from #43734 and #43726.

The 'trust' and 'reject' methods, as their name implies,
unconditionally allow and deny authentication of matching connections.

This patch introduces them as a prerequisite to later work on Unix
socket authentication, but also to introduce a bit of infrastructure
that binds new auth methods to a minimum required cluster
version. This new infrastructure ensures that future new auth methods
do not risk hosting a mixed-version cluster. (See discussion on #43717.)

The patch also introduces support for the 'local' rule prefix, which
is still unused.

@knz knz requested a review from madelynnblue January 6, 2020 07:02
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@knz knz force-pushed the 20200106-hba-rules branch 4 times, most recently from 7295e1b to 5192fab Compare January 6, 2020 10:25
}
host =
'host' %newHost ws
('host' %newHost | 'local' %newLocal) ws
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local connection type, as defined by the postgres docs, only has 3 following fields as opposed to host which has 4 or 5. I would prefer not adding local until our parser correctly supports the expected number of fields that local needs.

I'm reaching the point now where I no longer think ragel is a good fit for this problem. It was an experiment, and I consider it failed. It takes a long time to figure out how to use the language, and even then it is very easy to make blind mistakes. When we need to extend it 6-12 months later (as in here), it is difficult for the reviewer (me in this case, even though I was the original author) to remember how ragel works. The change you made a few days ago that correctly parsed single-letter comma-separated things for example, I didn't really understand what was going on, but it passed the tests so I hit accept.

Unless you really strongly disagree, or have a clean way to add the correct parsing for local, I suggest removing this addition.

https://blog.cloudflare.com/incident-report-on-memory-leak-caused-by-cloudflare-parser-bug/ seems like cloudflare had similar problems with ragel wrt maintainability.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I meant to say that I'm very on board with rewriting this parser in Go. It's not a super complicated language. It's annoying since it's sometimes space-separated except with double quotes. But I believe we could look at the pg implementation for some quick guidance about a well-tested way to write our parser.


// AnyVersion can be passed as minReqVersion to RegisterAuthMethod()
// to indicate there is no constraint on the cluster version.
const AnyVersion cluster.VersionKey = -1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a medium preference to remove this and force all auth methods to specify a real version. Can we use whatever the 19.2.0 release version was without breaking anybody? This would make it harder to misuse this feature (i.e., if someone copy-pasted an auth method with AnyVersion in it) and remove the need for special code that handles AnyVersion. Again, only medium preference, so if you feel that keeping it is better, that's fine too.

@knz knz force-pushed the 20200106-hba-rules branch from 5192fab to 89e72bc Compare January 7, 2020 22:35
Copy link
Copy Markdown
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFAL.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mjibson)


pkg/sql/pgwire/hba_conf.go, line 301 at r3 (raw file):

Previously, mjibson (Matt Jibson) wrote…

I have a medium preference to remove this and force all auth methods to specify a real version. Can we use whatever the 19.2.0 release version was without breaking anybody? This would make it harder to misuse this feature (i.e., if someone copy-pasted an auth method with AnyVersion in it) and remove the need for special code that handles AnyVersion. Again, only medium preference, so if you feel that keeping it is better, that's fine too.

Done.


pkg/sql/pgwire/hba/conf.rl, line 150 at r3 (raw file):

Previously, mjibson (Matt Jibson) wrote…

Oh, I meant to say that I'm very on board with rewriting this parser in Go. It's not a super complicated language. It's annoying since it's sometimes space-separated except with double quotes. But I believe we could look at the pg implementation for some quick guidance about a well-tested way to write our parser.

Done.

@knz knz force-pushed the 20200106-hba-rules branch from 89e72bc to db05674 Compare January 8, 2020 13:02
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Jan 8, 2020

TFYR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 8, 2020

Build failed

The 'trust' and 'reject' methods, as their name implies,
unconditionally allow and deny authentication of matching connections.

This patch introduces them as a prerequisite to later work on Unix
socket authentication, but also to introduce a bit of infrastructure
that binds new auth methods to a minimum required cluster
version. This new infrastructure ensures that future new auth methods
do not risk hosting a mixed-version cluster.

The patch also introduces support for the 'local' rule prefix, which
is still unused.

Release note (security): CockroachDB now supports the authentication
methods 'trust' and 'reject' in the cluster setting
server.host_based_authentication.configuration; their meaning is to
unconditionally allow and deny matching connection attempts.
@knz knz force-pushed the 20200106-hba-rules branch from db05674 to 3fe7e3c Compare January 8, 2020 13:22
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Jan 8, 2020

spurious error; retrying

bors r+

craig bot pushed a commit that referenced this pull request Jan 8, 2020
43731: pgwire,hba: introduce the 'trust' and 'reject' auth methods r=knz a=knz

First commits from #43734 and #43726.

The 'trust' and 'reject' methods, as their name implies,
unconditionally allow and deny authentication of matching connections.

This patch introduces them as a prerequisite to later work on Unix
socket authentication, but also to introduce a bit of infrastructure
that binds new auth methods to a minimum required cluster
version. This new infrastructure ensures that future new auth methods
do not risk hosting a mixed-version cluster. (See discussion on #43717.)

The patch also introduces support for the 'local' rule prefix, which
is still unused.


Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 8, 2020

Build succeeded

@craig craig bot merged commit 3fe7e3c into cockroachdb:master Jan 8, 2020
@knz knz deleted the 20200106-hba-rules branch January 8, 2020 13:55
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Jan 9, 2020

(used to fix #31113)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants