Skip to content

feat: cached auto-refreshing AWS credentials for BYOBucket#34380

Merged
nklaassen merged 1 commit into
masterfrom
nklaassen/byob-credentials
Nov 14, 2023
Merged

feat: cached auto-refreshing AWS credentials for BYOBucket#34380
nklaassen merged 1 commit into
masterfrom
nklaassen/byob-credentials

Conversation

@nklaassen
Copy link
Copy Markdown
Contributor

This commit implements an AWS credential generator and cache for the BYOBucket feature that provides AWS credentials that can be used by the v1 or v2 AWS SDKs for Go. These credentials are generated via an AWS OIDC integration: auth signs a JWT and we swap that with AWS STS for AWS some credentials that will allow us to access resources in the customer account.

These are provided via a "Configurator" which already needs to load the current cluster ExternalCloudAuditSpec, so it provides a couple extra conveniences that will be useful later:

  • IsUsed() reports whether to BYOBucket feature is currently configured to be actively used, and
  • GetSpec() returns the current active ExternalCloudAuditSpec

The part that feels a bit wrong is SetGenerateOIDCTokenFn - this is because of a chicken-egg problem where the audit log must be set up before the auth server can be created, but the auth server must be created to provide the OIDC signing facilities. This might be a bit more clear in following PRs where this is used.

@github-actions github-actions Bot requested review from atburke and r0mant November 9, 2023 06:55
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 9, 2023

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@github-actions github-actions Bot added audit-log Issues related to Teleports Audit Log size/lg labels Nov 9, 2023
@nklaassen nklaassen added the no-changelog Indicates that a PR does not require a changelog entry label Nov 9, 2023
@nklaassen nklaassen force-pushed the nklaassen/byob-credentials branch from 786e546 to c38df67 Compare November 9, 2023 07:13
Comment thread lib/auth/externalcloudaudit.go Outdated
Comment thread lib/events/externalcloudaudit/externalcloudaudit.go Outdated
Comment on lines +92 to +105
var useFips aws.FIPSEndpointState
if modules.GetModules().IsBoringBinary() {
useFips = aws.FIPSEndpointStateEnabled
}
cfg, err := config.LoadDefaultConfig(
ctx,
config.WithRegion(region),
config.WithUseFIPSEndpoint(useFips),
config.WithRetryMaxAttempts(10),
)
if err != nil {
return trace.Wrap(err)
}
o.stsClient = sts.NewFromConfig(cfg)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We have lib/cloud/clients.go which can return STS client. Would it make sense to use that so we're consistent in how we're creating clients everywhere? If it doesn't support FIPS endpoint yet, would make sense to add it there as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I gave this a try but lib/cloud/clients only offers v1 clients, and it's much more difficult to mock the v1 STS client in a way that satisfies https://pkg.go.dev/github.com/aws/aws-sdk-go@v1.47.9/aws/credentials/stscreds#NewWebIdentityRoleProviderWithOptions. Not sure it's worth the effort right now.

@nklaassen
Copy link
Copy Markdown
Contributor Author

friendly ping @atburke

This commit implements a "Configurator" for the BYOBucket feature that
provides AWS credentials that can be used by the v1 or v2 AWS SDKs for
Go.
These credentials are generated via an AWS OIDC integration: auth signs
a JWT and we swap that with AWS STS for AWS credentials.
It also reports whether or not the BYOB feature `IsUsed()` currently,
and provides access to the current cluster ExternalCloudAudit spec.

This looks a bit weird because of a chicken-egg problem where the audit
log must be set up before the auth server can be created, but the auth
server must be created to provide the OIDC signing facilities.
This will be more clear in following PRs.
@nklaassen nklaassen force-pushed the nklaassen/byob-credentials branch from afcc154 to 5eaacde Compare November 14, 2023 17:31
@nklaassen nklaassen enabled auto-merge November 14, 2023 17:37
@nklaassen nklaassen added this pull request to the merge queue Nov 14, 2023
Merged via the queue into master with commit ad9191e Nov 14, 2023
@nklaassen nklaassen deleted the nklaassen/byob-credentials branch November 14, 2023 20:36
github-merge-queue Bot pushed a commit that referenced this pull request Nov 20, 2023
* [v14] external cloud audit proto

Backport #33022 to branch/v14

* [v14] external_cloud_audit: add resource layer

Backport #32833 to branch/v14

* [v14] feat: IAM permissions for BYOBucket

Backport #33416 to branch/v14

This commit adds a one-off teleport command that configures the
necessary IAM permissions for the upcoming External Cloud Audit
(BYOBucket) feature.

An example command invocation looks like:
```
$ teleport integration configure externalcloudaudit-iam \
  --aws-region us-west-2 --role nic-byob-test --policy nic-byob \
  --session-recordings s3://nic-byob/sess-rec-v2 \
  --audit-events s3://nic-byob/events --athena-results s3://nic-byob/results \
  --athena-workgroup primary --glue-database nic_byob --glue-table nic_byob_table
```

In normal usage this command will be generated for the user so that they
can just copy a command from the Web UI and run it in AWS CloudShell.

The permissions generated here are based on
https://github.com/gravitational/cloud/blob/rfd/77-bring-your-own-bucket/rfd/0077-Bring-your-own-bucket.md,
but only include the permissions necessary for using the feature at
runtime and not any permissions necessary to bootstrap/create the
resources.

* [v14] feat: generate randomized ExternalCloudAudit config

Backport #33555 to branch/v14

* [v14] BYOB: Bootstrap Athena Infrastructure

Backport #33272 to branch/v14

* [v14] feat: cached auto-refreshing AWS credentials for BYOBucket

Backport #34380 to branch/v14

This commit implements a "Configurator" for the BYOBucket feature that
provides AWS credentials that can be used by the v1 or v2 AWS SDKs for
Go.
These credentials are generated via an AWS OIDC integration: auth signs
a JWT and we swap that with AWS STS for AWS credentials.
It also reports whether or not the BYOB feature `IsUsed()` currently,
and provides access to the current cluster ExternalCloudAudit spec.

This looks a bit weird because of a chicken-egg problem where the audit
log must be set up before the auth server can be created, but the auth
server must be created to provide the OIDC signing facilities.
This will be more clear in following PRs.

* [v14] fix: correct IAM policies for BYOB

Backport #34484 to branch/v14

This commit fixes the IAM policies generated by the oneoff
externalcloudaudit bootstrap command based on manual testing, and brings
them more in line with the original RFD
https://github.com/gravitational/cloud/blob/master/rfd/0077-Bring-your-own-bucket.md

* [v14] feat: enable External Cloud Audit backend

Backport #34606 to branch/v14

This commit enables the External Cloud Audit (BYOBucket) feature with a
fully functional backend by setting up the Athena and S3 audit
components with the right AWS configurations and resource locations.

* [v14] Add ExternalCloudAudit permissions to user context ACL

Backport #34289 to branch/v14

---------

Co-authored-by: Tobiasz Heller <14020794+tobiaszheller@users.noreply.github.com>
Co-authored-by: Logan Davis <38335829+logand22@users.noreply.github.com>
Co-authored-by: matheus <matheus.battirola@goteleport.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit-log Issues related to Teleports Audit Log no-changelog Indicates that a PR does not require a changelog entry size/lg

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants