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

[v17] Remove S3 params from AWS OIDC IdP set up script #51191

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 7 additions & 46 deletions lib/web/integrations_awsoidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ package web

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"log/slog"
"maps"
"net/http"
"net/url"
"slices"
"strings"

Expand Down Expand Up @@ -1360,14 +1357,21 @@ func (h *Handler) awsOIDCConfigureIdP(w http.ResponseWriter, r *http.Request, p
return nil, trace.BadParameter("invalid role %q", role)
}

proxyAddr, err := oidc.IssuerFromPublicAddress(h.cfg.PublicProxyAddr, "")
if err != nil {
return nil, trace.Wrap(err)
}

// The script must execute the following command:
// teleport integration configure awsoidc-idp
argsList := []string{
"integration", "configure", "awsoidc-idp",
fmt.Sprintf("--cluster=%s", shsprintf.EscapeDefaultContext(clusterName)),
fmt.Sprintf("--name=%s", shsprintf.EscapeDefaultContext(integrationName)),
fmt.Sprintf("--role=%s", shsprintf.EscapeDefaultContext(role)),
fmt.Sprintf("--proxy-public-url=%s", shsprintf.EscapeDefaultContext(proxyAddr)),
}

policyPreset := queryParams.Get("policyPreset")
if err := awsoidc.ValidatePolicyPreset(awsoidc.PolicyPreset(policyPreset)); err != nil {
return nil, trace.Wrap(err)
Expand All @@ -1376,49 +1380,6 @@ func (h *Handler) awsOIDCConfigureIdP(w http.ResponseWriter, r *http.Request, p
argsList = append(argsList, fmt.Sprintf("--policy-preset=%s", shsprintf.EscapeDefaultContext(policyPreset)))
}

// We have two set up modes:
// - use the Proxy HTTP endpoint as Identity Provider
// - use an S3 Bucket for storing the public keys
//
// The script will pick a mode depending on the query params received here.
// If the S3 location was defined, then it will use that mode and upload the Public Keys to the S3 Bucket.
// Otherwise, it will create an IdP pointing to the current Cluster.
//
// Whatever the chosen mode, the Proxy HTTP endpoint will always return the public keys.
s3Bucket := queryParams.Get("s3Bucket")
s3Prefix := queryParams.Get("s3Prefix")

switch {
case s3Bucket == "" && s3Prefix == "":
proxyAddr, err := oidc.IssuerFromPublicAddress(h.cfg.PublicProxyAddr, "")
if err != nil {
return nil, trace.Wrap(err)
}

argsList = append(argsList,
fmt.Sprintf("--proxy-public-url=%s", shsprintf.EscapeDefaultContext(proxyAddr)),
)

default:
if s3Bucket == "" || s3Prefix == "" {
return nil, trace.BadParameter("s3Bucket and s3Prefix query params are required")
}
s3URI := url.URL{Scheme: "s3", Host: s3Bucket, Path: s3Prefix}

jwksContents, err := h.jwks(r.Context(), types.OIDCIdPCA, true)
if err != nil {
return nil, trace.Wrap(err)
}
jwksJSON, err := json.Marshal(jwksContents)
if err != nil {
return nil, trace.Wrap(err)
}
argsList = append(argsList,
fmt.Sprintf("--s3-bucket-uri=%s", shsprintf.EscapeDefaultContext(s3URI.String())),
fmt.Sprintf("--s3-jwks-base64=%s", base64.StdEncoding.EncodeToString(jwksJSON)),
)
}

script, err := oneoff.BuildScript(oneoff.OneOffScriptParams{
TeleportArgs: strings.Join(argsList, " "),
SuccessMessage: "Success! You can now go back to the Teleport Web UI to use the integration with AWS.",
Expand Down
52 changes: 11 additions & 41 deletions lib/web/integrations_awsoidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package web

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"net/url"
Expand Down Expand Up @@ -613,11 +612,6 @@ func TestBuildAWSOIDCIdPConfigureScript(t *testing.T) {
}
scriptEndpoint := publicClt.Endpoint(pathVars...)

jwksEndpoint := publicClt.Endpoint(".well-known", "jwks-oidc")
resp, err := publicClt.Get(ctx, jwksEndpoint, nil)
require.NoError(t, err)
jwksBase64 := base64.StdEncoding.EncodeToString(resp.Bytes())

tests := []struct {
name string
reqRelativeURL string
Expand All @@ -631,17 +625,14 @@ func TestBuildAWSOIDCIdPConfigureScript(t *testing.T) {
"awsRegion": []string{"us-east-1"},
"role": []string{"myRole"},
"integrationName": []string{"myintegration"},
"s3Bucket": []string{"my-bucket"},
"s3Prefix": []string{"prefix"},
"policyPreset": []string{""},
},
errCheck: require.NoError,
expectedTeleportArgs: "integration configure awsoidc-idp " +
"--cluster=localhost " +
"--name=myintegration " +
"--role=myRole " +
`--s3-bucket-uri=s3://my-bucket/prefix ` +
"--s3-jwks-base64=" + jwksBase64,
"--proxy-public-url=" + proxyPublicURL.String(),
},
{
name: "valid with proxy endpoint",
Expand All @@ -663,16 +654,13 @@ func TestBuildAWSOIDCIdPConfigureScript(t *testing.T) {
"awsRegion": []string{"us-east-1"},
"role": []string{"Test+1=2,3.4@5-6_7"},
"integrationName": []string{"myintegration"},
"s3Bucket": []string{"my-bucket"},
"s3Prefix": []string{"prefix"},
},
errCheck: require.NoError,
expectedTeleportArgs: "integration configure awsoidc-idp " +
"--cluster=localhost " +
"--name=myintegration " +
"--role=Test\\+1=2,3.4\\@5-6_7 " +
`--s3-bucket-uri=s3://my-bucket/prefix ` +
"--s3-jwks-base64=" + jwksBase64,
"--proxy-public-url=" + proxyPublicURL.String(),
},
{
name: "valid with supported policy preset",
Expand All @@ -687,42 +675,20 @@ func TestBuildAWSOIDCIdPConfigureScript(t *testing.T) {
"--cluster=localhost " +
"--name=myintegration " +
"--role=myRole " +
"--policy-preset=aws-identity-center " +
"--proxy-public-url=" + proxyPublicURL.String(),
"--proxy-public-url=" + proxyPublicURL.String() + " " +
"--policy-preset=aws-identity-center",
},
{
name: "missing role",
reqQuery: url.Values{
"integrationName": []string{"myintegration"},
"s3Bucket": []string{"my-bucket"},
"s3Prefix": []string{"prefix"},
},
errCheck: isBadParamErrFn,
},
{
name: "missing integration name",
reqQuery: url.Values{
"role": []string{"role"},
"s3Bucket": []string{"my-bucket"},
"s3Prefix": []string{"prefix"},
},
errCheck: isBadParamErrFn,
},
{
name: "missing s3 bucket",
reqQuery: url.Values{
"integrationName": []string{"myintegration"},
"role": []string{"role"},
"s3Prefix": []string{"prefix"},
},
errCheck: isBadParamErrFn,
},
{
name: "missing s3 prefix",
reqQuery: url.Values{
"integrationName": []string{"myintegration"},
"role": []string{"role"},
"s3Bucket": []string{"my-bucket"},
"role": []string{"role"},
},
errCheck: isBadParamErrFn,
},
Expand All @@ -731,9 +697,13 @@ func TestBuildAWSOIDCIdPConfigureScript(t *testing.T) {
reqQuery: url.Values{
"integrationName": []string{"myintegration"},
"role": []string{"role"},
"s3Bucket": []string{"my-bucket"},
},
errCheck: isBadParamErrFn,
expectedTeleportArgs: "integration configure awsoidc-idp " +
"--cluster=localhost " +
"--name=myintegration " +
"--role=role " +
"--proxy-public-url=" + proxyPublicURL.String(),
errCheck: require.NoError,
},
}

Expand Down
2 changes: 0 additions & 2 deletions web/packages/teleport/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,6 @@ export interface UrlDeployServiceIamConfigureScriptParams {
export interface UrlAwsOidcConfigureIdp {
integrationName: string;
roleName: string;
s3Bucket?: string;
s3Prefix?: string;
policyPreset?: AwsOidcPolicyPreset;
}

Expand Down
Loading