Commit Graph

1151 Commits

Author SHA1 Message Date
Benjamin A. Petersen
337459feb0 Update webhook status integration tests
- total api fields test 260->261
2024-03-19 16:48:05 -04:00
Benjamin A. Petersen
590e2d18f7 Add WebhookAuthenticator integration tests, expand unit tests
- Add WebhookAuthenticator unit tests, update generated code
- Add validateTLSNegotiation(), update tests
- Update validateTLSNegotiation, add unit tests, factor out helpers
- Update generated code
2024-03-19 16:48:05 -04:00
Benjamin A. Petersen
ef36b454ba Improve WebhookAuthenticator Status and Validations
- Validate TLS Configuration
- Validate Endpoint
- Validate TLS Negotiation
  - Report status handshake negotiation with webhook
- Unit tests
- Integration tests
2024-03-19 16:48:03 -04:00
Joshua Casey
bc8aebeffe Use go.uber.org/mock instead of github.com/golang/mock and rerun mock generation 2024-03-11 13:42:30 -05:00
Joshua Casey
ffc49d96b3 Integration tests should use a valid value for CredentialIssuer spec.impersonationProxy.service.type 2024-03-08 11:19:15 -06:00
Joshua Casey
ab0682917a whoami integration test now allows for additional extra fields in K8s 1.30+ 2024-03-07 08:09:16 -06:00
Benjamin A. Petersen
e8482ab9e9 Update jwtauthenticator unit tests to check actions
- Add test to verify timestamps are particularly updated
- Improve diff output in tests for actions
- Make jwtauthenticator status tests parallel
- Update copyright headers in multiple files
2024-02-27 15:45:32 -08:00
Benjamin A. Petersen
42acf8dcce Add Status & tests for jwks key fetching 2024-02-27 15:45:32 -08:00
Benjamin A. Petersen
1c7e7048a8 Update copyright year in modified files 2024-02-27 15:45:32 -08:00
Benjamin A. Petersen
73e4d3144b Add integration tests for JWTAuthenticators
- paired with changes to e2e_test.go, adds Status.Condition assertions
  around JWTAuthenticators
2024-02-27 15:45:32 -08:00
Benjamin A. Petersen
084c3114f4 Improve jwtcachefiller tests
- some format updates
- add timestamp to test
- fix order of expect,actual in some assertions
- remove some commented code no longer needed
2024-02-27 15:45:32 -08:00
Benjamin A. Petersen
47639340ec extract status comparison test helpers 2024-02-27 15:45:32 -08:00
Benjamin A. Petersen
fd14a5794e ldap upstream watcher: rename local var for clarity 2024-02-27 15:45:32 -08:00
Benjamin A. Petersen
a4447fa606 Add .Status to JWTAuthenticator with Conditions,Phase
- "Ready" condition & supporting conditions
- Legacy "Phase" for convenience
- Refactor newCachedJWTAuthenticator() func
  to improve ability to provide additional conditions
- Update JWTAuthenticator.Status type
- Update RBAC for SA to get/watch/update JWTAuthenticator.Status
- Update logger to plog, add tests for logs & statuses
- update Sync() to reduce enqueue when error is config/user managed, perhaps remove validateJWKSResponse()
2024-02-27 15:45:32 -08:00
Ryan Richard
0d31e955ae Don't skip upstream group memberships when groups scope is not granted
Background: For dynamic clients, the groups scope is not always allowed
and/or requested by the client, so it will not always be granted by the
Supervisor for an authorization request.

Previously, when the groups scope was not granted, we would skip
searching for upstream groups in some scenarios.

This commit changes the behavior of authorization flows so that even
when the groups scope is not granted we still search for the upstream
group memberships as configured, and we pass the upstream group
memberships into any configured identity transformations. The identity
transformations could potentially reject the user's authentication based
on their upstream group membership.

When the groups scope is not granted, we don't include the groups in
the final Supervisor-issued ID token. This behavior is not changed.
2024-02-21 13:12:18 -08:00
Ryan Richard
4b4a4ad592 Rename a func and collapse applying id transforms into creating session 2024-02-20 14:47:28 -08:00
Ryan Richard
b341e52214 Refactor to move invocation of identity transforms out of IDP interfaces
Each endpoint handler is now responsible for applying the identity
transformations and creating most of the session data, rather than each
implementation of the upstream IDP interface. This shares code better,
and reduces the responsibilities of the implementations of the IDP
interface by letting them focus more on the upstream stuff.

Also refactor the parameters and return types of the IDP interfaces to
make them more clear, and because they can be more focused on upstream
identities (pre-identity transformation). This clarifies the
responsibilities of the implementations of the IDP interface.
2024-02-20 10:45:54 -08:00
Ryan Richard
1e8e7b948e Refactor token endpoint to add interface for IDP upstream refresh 2024-02-20 09:26:34 -08:00
Ryan Richard
1bc13e94f7 Refactor to extract interface for upstream IDP interactions
Create an interface to abstract the upstream IDP from the
authorize, IDP discovery, callback, choose IDP, and login
endpoints. This commit does not refactor the token endpoint,
which will be refactored in a similar way in the next commit.
2024-02-20 09:26:34 -08:00
Ryan Richard
9db87132b1 More refactoring of auth handler and related refactor of upstreamldap
- continued refactoring the auth handler to share more code between
  the two supported browserless flows: OIDC and LDAP/AD
- the upstreamldap package should not know about the concept of
  OIDC granted scopes, so refactored it to be a skipGroups bool
2024-02-20 09:26:34 -08:00
Ryan Richard
9992855cb8 Refactor error handling in authorize endpoint (changes some responses)
- Simplify the error handling in the authorize endpoint by making the
  private helper functions return fosite-style errors, and having
  one place that writes those errors to the response.
- Some types of errors were previously returned as regular http-style
  errors. Those have all been converted to be returned as oauth-style
  errors (which can be redirects to the client), except for http method
  not found errors. This is a change in behavior from the client's point
  of view, but only when those unexpected errors happen. These types of
  errors are more consistent with RFC6749 section 4.1.2.1.
- Avoids using the httperr package for error handling.
- Create a struct for the handler as a first step toward making smaller
  functions with fewer parameters.
2024-02-20 09:26:34 -08:00
Ryan Richard
cf82cf996e Adjust tests and comments for upgrade to latest version of fosite 2024-02-13 10:16:41 -08:00
Ryan Richard
dce9409ccc login oidc cmd checks access token expiry before doing token exchange
In the RFC8693 token exchange, the CLI sends your access token and
receives in exchange a new cluster-scoped ID token.

Fix a bug in the CLI. Whenever the "pinniped login oidc" command was
planning to perform the RFC8693 token exchange, it failed to check if
the cached access token was still valid before performing the exchange,
which sends the access token. It instead checked if the cached ID token
was still valid, but that it not relevant in this situation because the
ID token is not going to be used for anything (instead the new ID token
returned by the RFC8693 token exchange will be used for auth).

This bug doesn't actually matter today, because the Supervisor-issued
access and ID tokens always both have the same 2-minute lifetimes.
However, future enhancements may cause them to have different lifetimes
in certain circumstances. Fixing this CLI bug now to prepare for those
potential future enhancements.
2024-02-09 13:33:30 -08:00
Ryan Richard
904a60f04a Fix ptls_test.go for Go 1.22 2024-02-08 14:13:09 -08:00
Ryan Richard
560ee45b50 Fix plog_test.go for Go 1.22 2024-02-08 11:53:59 -08:00
Ryan Richard
d2794114f4 Revert support TLS 1.3 in FIPS mode because Go reverted goboring upgrade
Goboring only allows TLS 1.2.

The next goboring will allow both TLS 1.2 and TLS 1.3. We got a preview
of this when the Go team upgraded goboring in Go 1.21.6, but then
downgraded it again in the next Go releases.

When the Go team eventually upgrades goboring again, then we can
revert this commit to bring back TLS 1.3 support in FIPS mode.
2024-02-08 10:43:52 -08:00
Ryan Richard
e303a45dd1 Test util AssertTLS supports both old and new goboring
- Current goboring only allows TLS 1.2.
- The next goboring will allow TLS 1.2 and TLS 1.3. We got a preview
  of this when the Go team upgraded goboring in Go 1.21.6, but then
  downgraded it again in the next Go releases.
2024-02-08 09:39:01 -08:00
Ryan Richard
50e4d6db6c Support the new Go FIPS compiler which was upgraded inside Go 1.21.6
The release of Go 1.21.6 includes the new boring crypto when compiling
with FIPS enabled. See https://go.dev/doc/devel/release#go1.21.0 and
https://github.com/golang/go/issues/64717.

This new version of boring crypto allows the use of TLS v1.3 for the
first time, so we changed the Pinniped code to use TLS v1.3 where
appropriate when compiled with the FIPS compiler. It also changed the
allowed TLS v1.2 ciphers, so we updated those as well.

After this commit, the project must be compiled by at least Go v1.21.6
when compiling in fips mode. The hack/Dockerfile_fips was already
updated to use that version of Go in a previous commit.

Co-authored-by: Benjamin A. Petersen <ben@benjaminapetersen.me>
2024-01-18 14:23:26 -08:00
Ryan Richard
c7299f4daf Update dependencies, including Kube packages to v0.29.0 2024-01-04 12:30:22 -08:00
Ryan Richard
a4883507b5 Disable UnauthenticatedHTTP2DOSMitigation feature gate 2023-12-12 08:47:03 -08:00
Ryan Richard
c5d1f380d2 revert the disabling of http2 for the Supervisor OIDC endpoints
Due to the unintended consequence of potentially breaking Ingresses
which were configured to use http2 on their backends.
2023-12-06 13:10:51 -08:00
Ryan Richard
4b7b9e4362 Defensive changes to mitigate potential http2 rapid reset attacks 2023-12-05 14:57:50 -08:00
Ryan Richard
e1954b1df9 update session storage version from 5 to 6 due to fosite upgrade
A small part of the session storage changed type in the latest version
of fosite compared to the old version of fosite that we were using.
Just to be safe, update our session storage version to invalidate
any pre-existing sessions upon upgrade of Pinniped.
2023-12-04 14:49:22 -08:00
Ryan Richard
37c2ce53d7 upgrade fosite pkg to latest 2023-12-04 14:49:21 -08:00
Ryan Richard
ca5ad85bbd Switch from gopkg.in/square/go-jose.v2 to github.com/go-jose/go-jose/v3
Made the switch wherever possible, but since fosite still uses the old
gopkg.in/square/go-jose.v2 there was one test where we still need to use
it as a direct dependency.
2023-12-04 11:05:12 -08:00
Ryan Richard
8296093beb Increase fudge factor in tokenclient_test.go due to CI failures 2023-12-04 10:04:05 -08:00
Ryan Richard
7616799adb Minor refactors in legacy SA token Secret cleanup controller 2023-11-30 16:40:21 -08:00
Ryan Richard
dea3513125 Add test for when no SA token is cached in impersonator_test.go 2023-11-30 15:55:27 -08:00
Ryan Richard
5f4645d505 Improve unit tests in tokenclient_test.go
Also fix a linter error and rename some new files.
2023-11-30 13:29:52 -08:00
Joshua Casey
c439cc03a2 WIP for a tokenClient.Start() unit test 2023-11-30 09:57:57 -08:00
Joshua Casey
2603bbfcd6 Do not use long-lived service account tokens in secrets
Co-authored-by: Ryan Richard <richardry@vmware.com>
2023-11-30 09:57:57 -08:00
Joshua Casey
b68e7f3e9e Lightly standardize import aliases 2023-11-15 13:52:17 -06:00
Joshua Casey
3f92a546df Unit test fixes 2023-11-05 20:53:12 -06:00
Joshua Casey
bf1366412a Unit test fixes
Co-authored-by: Joshua Casey <joshuatcasey@gmail.com>
Co-authored-by: Ryan Richard <richardry@vmware.com>
2023-11-02 14:17:29 -05:00
Ryan Richard
29e939db7f Upgrade the linter to golangci-lint@v1.55.1
The unused-parameter linter became stricter, so we adjust it to
allow unused params that start with underscore. It can be nice to keep
unused param names when implementing an interface sometimes, to help
readers understand why it is unused in that particular implementation.
2023-11-02 09:54:16 -07:00
Ryan Richard
54d4879c69 Merge pull request #1742 from vmware-tanzu/idp_chooser_ui
show interstitial web page to allow user to choose IDP when multiple IDPs are configured and authorize endpoint query param to choose IDP is not used
2023-10-30 15:32:57 -07:00
Joshua Casey
3c33c59aa9 Update unit tests 2023-10-30 15:40:17 -05:00
Ryan Richard
0501159ac0 Show an IDP chooser UI when appropriate from authorize endpoint 2023-10-30 11:05:53 -07:00
Ryan Richard
62c597eb3b Show errors from the form_post POST request on the page 2023-10-02 09:53:53 -07:00
Ryan Richard
ca6c29e463 Fix deadlock during shutdown which prevented leader election cleanup
Before this fix, the deadlock would prevent the leader pod from giving
up its lease, which would make it take several minutes for new pods to
be allowed to elect a new leader. During that time, no Pinniped
controllers could write to the Kube API, so important resources were not
being updated during that window. It would also make pod shutdown take
about 1 minute.

After this fix, the leader gives up its lease immediately, and pod
shutdown takes about 1 second. This improves restart/upgrade time and
also fixes the problem where there was no leader for several minutes
after a restart/upgrade.

The deadlock was between the post-start hook and the pre-shutdown hook.
The pre-shutdown hook blocked until a certain background goroutine in
the post-start hook finished, but that goroutine could not finish until
the pre-shutdown hook finished. Thus, they were both blocked, waiting
for each other infinitely. Eventually the process would be externally
killed.

This deadlock was most likely introduced by some change in Kube's
generic api server package related to how the many complex channels used
during server shutdown interact with each other, and was not noticed
when we upgraded to the version which introduced the change.
2023-09-20 16:54:24 -07:00