Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for GSuite logins #3122

Merged
merged 1 commit into from
Nov 5, 2019
Merged

Fix support for GSuite logins #3122

merged 1 commit into from
Nov 5, 2019

Conversation

klizhentas
Copy link
Contributor

This commit fixes support for GSuite logins
by using service accounts for access purposes.

The resulting connector now looks like:

kind: oidc
version: v2
metadata:
  name: gsuite
spec:
  redirect_url: https://example.com/v1/webapi/oidc/callback
  client_id: exampleclientid.apps.googleusercontent.com
  client_secret: exampleclientsecret
  issuer_url: https://accounts.google.com
  # Notice that scope here is not requiested from OIDC exchange anymore, this scope
  #
  # https://www.googleapis.com/auth/admin.directory.group.readonly
  #
  # is now implicitly requested by the client
  #
  scope: ['openid', 'email']
  # The setup below is involved and requires careful following of the guides:
  #
  # https://developers.google.com/admin-sdk/directory/v1/guides/delegation
  # https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority
  #
  # The service account scope has to be set to
  #
  # https://www.googleapis.com/auth/admin.directory.group.readonly
  google_service_account_file: "/home/sasha/google/gsuite-creds.json"
  google_admin_email: "sasha@gravitational.com"
  claims_to_roles:
    - {claim: "groups", value: "dev@gravitational.com", roles: ["clusteradmin"]}

@klizhentas
Copy link
Contributor Author

Folks, please review once you get a chance.

@benarent some open questions:

  • I have used google_service_account_file approach instead of adding JSON to yaml. This has it's advantages and disadvantages.

Cons:

  • The file has to be distributed on every auth server that supports this in HA mode
  • OIDC connector is not self-sufficient and portable

Pros:

  • Mounted and external service accounts can be used with this approach, rotated and short term ones in GKE for example
  • Less potential for mistakes

Please review with the product team, and either way, we have to make a call.

There is additional changes - the service account approach will only work if it impersonates the request from some real user, in my example it's me. That's why I had to add this as an additional field.

The scope no longer requests the admin.groups.readonly, because it will break the login screen, and instead reuqests it via serviceaccount.

Domain wide delegation should be enabled and it takes a couple of minutes to kick in sometimes.

Needless to say this needs guide update as well.

@benarent benarent added this to the 4.2 "Alameda" milestone Nov 4, 2019
@webvictim
Copy link
Contributor

Fixes #3029

Copy link
Contributor

@fspmarshall fspmarshall left a comment

Choose a reason for hiding this comment

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

In general, it seems better to not have reliance on local state be the default behavior. Perhaps the google_service_account_file field could be peeked for a file:// scheme prefix, and otherwise interpreted as in-line json?

@benarent
Copy link
Contributor

benarent commented Nov 5, 2019

Extra note: When managing service access via Google Admin, these are the two permissions needed.

https://www.googleapis.com/auth/admin.directory.group.member.readonly, https://www.googleapis.com/auth/admin.directory.group.readonly

@benarent
Copy link
Contributor

benarent commented Nov 5, 2019

I noticed that this change added

google_admin_email: ""
google_service_account_file: ""

into my already exsiting OIDC connectors, I copied over https://gravitational.com/teleport/docs/oidc/#oidc-connector-configuration , and this was the result.

Is it possible to not add it into the connector? Or is it required for validation? I don't want to create extra confusion for 0Auth and KeyClock users.

image

@klizhentas
Copy link
Contributor Author

@benarent I think I can fix that

@klizhentas
Copy link
Contributor Author

@benarent fixed

@benarent
Copy link
Contributor

benarent commented Nov 5, 2019

We reviewed the config options this morning and we are recommending to use Forrests suggestion of using file:// URI schema, similar to the current process for Gravity Image Manifest Format. https://gravitational.com/gravity/docs/pack/

This commit fixes support for GSuite logins
by using service accounts for access purposes.

The resulting connector now looks like:

```yaml
kind: oidc
version: v2
metadata:
  name: gsuite
spec:
  redirect_url: https://example.com/v1/webapi/oidc/callback
  client_id: exampleclientid.apps.googleusercontent.com
  client_secret: exampleclientsecret
  issuer_url: https://accounts.google.com
  # Notice that scope here is not requiested from OIDC exchange anymore, this scope
  #
  # https://www.googleapis.com/auth/admin.directory.group.readonly
  #
  # is now implicitly requested by the client
  #
  scope: ['openid', 'email']
  # The setup below is involved and requires careful following of the guides:
  #
  # https://developers.google.com/admin-sdk/directory/v1/guides/delegation
  # https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority
  #
  # The service account scopes have to be set to
  #
  # https://www.googleapis.com/auth/admin.directory.group.readonly
  # https://www.googleapis.com/auth/admin.directory.group.member.readonly
  #
  # the following paths are supported:
  # 1. plain path
  # /var/lib/secrets/gsuite-creds.json
  #
  # 2. explicit scheme file://
  # file:///var/lib/secrets/gsuite-creds.json
  #
  # other schemes are not supported at the moment
  #
  google_service_account_file: "/var/lib/secrets/gsuite-creds.json"
  google_admin_email: "admin@example.com"
  claims_to_roles:
    - {claim: "groups", value: "admin@example.com", roles: ["clusteradmin"]}
```
@klizhentas
Copy link
Contributor Author

@benarent @russjones @fspmarshall please re-review. I've updated the docs in the commit as well with the changes.

Have adopted the file:/// scheme and changed the name of the google_service_account_file to google_service_account_uri to match our conventions.

Inline json is not supported as well as any other schemes for now.

Copy link
Contributor

@benarent benarent left a comment

Choose a reason for hiding this comment

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

Just updated my cluster and successfully tested the updated G Suite service key URI.

@klizhentas
Copy link
Contributor Author

retest this please

@klizhentas klizhentas merged commit 762db69 into branch/4.1 Nov 5, 2019
@benarent benarent mentioned this pull request Nov 9, 2019
6 tasks
@klizhentas klizhentas deleted the sasha/gsuite branch March 15, 2021 16:51
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.

4 participants