Skip to content

[v11] Backport enterprise SSO refactor PRs#20243

Closed
camscale wants to merge 5 commits intobranch/v11from
camh/backport-refactor-sso/branch/v11
Closed

[v11] Backport enterprise SSO refactor PRs#20243
camscale wants to merge 5 commits intobranch/v11from
camh/backport-refactor-sso/branch/v11

Conversation

@camscale
Copy link
Copy Markdown
Contributor

@camscale camscale commented Jan 14, 2023

Backport the enterprise SSO refactor PRs that are the first step to
moving the enterprise SSO connectors to the enterprise repository.

This is the first of 4 PRs to backport the enterprise SSO connector
migration to the v11 branch. The 4 PRs are (including this):

The PRs backported in this PR are:

Conflicts resolved:

  • PR [v11] Deprecate old SSH session tracking logic #17604: Deprecate old SSH session tracking logic
    • This PR added some code-adjacent to code that was removed - a simple
      textual conflict
    • The handler installation it added needed some tweaks to use
      now-exported methods: s/withAuth/WithAuth/
  • PR [v11] inventory heartbeats #19938: inventory heartbeats
    • This PR made a code-adjacent change to a struct field removal - a
      simple textual conflict again.

These changes are just a refactor to make it easier to migrate the code.
No functional changes are present.

Issue: https://github.com/gravitational/teleport.e/issues/525

Export some names in the `lib/auth` package so that SSO auth plugins can
be implemented from outside this package, adding doc comments where missing:

  * struct `ssoRequestParams` (including fields)
  * struct `ssoCallbackResponse` (including fields)
  * func `parseSSORequestParams`
  * func `ssoSetWebSessionAndRedirectURL`
  * func `redirectURLWithError`
  * var `ssoLoginConsoleErr`, renamed to `SSOLoginFailureMessage`
  * type `CachedSessionLingeringThreshold` (for TestSAML)
Create a new type - `SAMLAuthService` - and move the implementation of
the SAML connector from the auth Service to this new type. This
decoupling will make it easier to move out of tree in a later commit.

This also lays the basic groundwork for running without the SAML
connector at all, returning a NotImplemented error for all the SAML
logic if the SAMLAuthService is not plugged in.

A number of names in the `auth` package have been exported to facilitate
moving the SAML connector out of this repository. The types exported do
not need to be exported for this commit, but for subsequent commits that
move the `SAMLAuthService` out of the `auth` package.

Also apply a small fix to to emit `apievents.SAMLConnector*` events of
`apievents.OIDCConnector*` events in the SAML connector.
Remove the Upsert and Delete methods from the SAMLService interface. It
was intended for these to be part of the SAML "plugin", however they are
needed for the operator tests to be able to create and delete the SAML
connectors.

The methods are back to being implemented directly in the `auth.Server`.
This does not cause any real issues with the rest in the enterprise repo
as the upsert/delete logic is just manipulating the local backend with
no actual SAML logic in it. The `Get*` methods had already been kept in
the `auth.Server` for the same reason.

This narrows the `SAMLService` interface to just creating the SAML auth
request and validating the response that comes back from the SAML
identity provider. This is the core of the SAML-specific logic.

Issue: gravitational/teleport.e#525
Provide defaults for `TestTLSServerConfig` when passed to
`auth.NewTestServer()`, as some of those fields cannot be set from
outside `NewTestServer()`. The defaults are the same as when called
without a `TestTLSServerConfig`, which allows just some fields to be
set/overridden.

This is to allow `APIConfig.PluginRegistry` to be set.
Refactor the OIDC connector to its own type so it is simpler to move out
of the `auth.Server` struct. This follows the same pattern as was done
with the SAML connector - a new struct that the OIDC request methods are
attached to, plugged into the `auth.Server`.

Move some small amount of code around so when it comes to removing it
later, it is largely confined to the oidc files and large contiguous
blocks - makes it slightly simpler to review.

Make `ValidateACRValues` a pure function as it did not use anything from
the struct it was a method on, and move the test for it into
`oidc_test.go`.

Move `isHTTPS()` from `auth.go` to `oidc.go` as it is only used there
and will later move out.

Export `validateOIDCAuthCallbackReq` and `oidcAuthRawResponse` and move
them to `oidc.go` so the web handler can also be moved to enterprise.
@camscale camscale marked this pull request as ready for review January 14, 2023 12:55
@github-actions github-actions Bot requested review from Tener, strideynet and zmb3 January 14, 2023 12:56
@camscale camscale requested a review from r0mant January 14, 2023 12:57
@camscale camscale closed this Feb 7, 2023
@camscale camscale deleted the camh/backport-refactor-sso/branch/v11 branch April 6, 2023 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant