Skip to content

Commit

Permalink
AWS OIDC: Script to configure EC2 Auto Discover with SSM (#41053) (#4…
Browse files Browse the repository at this point in the history
…1393)

* AWS OIDC: Script to configure EC2 Auto Discover with SSM

There's a new teleport command that adds an inline policy which enables
the AWS OIDC Integration to handle EC2 Auto Discover using the script
mode (SSM).
It also adds the SSM Document used in the teleport installation.

There's also a new endpoint which returns the one off script that uses
that command.

* Update lib/integrations/awsoidc/ec2_ssm_iam_config.go



---------

Co-authored-by: Edward Dowling <[email protected]>
  • Loading branch information
marcoandredinis and EdwardDowling authored May 16, 2024
1 parent be9788d commit 9018a36
Show file tree
Hide file tree
Showing 18 changed files with 611 additions and 20 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6
github.com/aws/aws-sdk-go-v2/service/sns v1.26.7
github.com/aws/aws-sdk-go-v2/service/sqs v1.29.7
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.2
github.com/aws/aws-sdk-go-v2/service/sts v1.28.5
github.com/aws/aws-sigv4-auth-cassandra-gocql-driver-plugin v0.0.0-20220331165046-e4d000c0d6a6
github.com/aws/smithy-go v1.20.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ github.com/aws/aws-sdk-go-v2/service/sns v1.26.7 h1:DylmW2c1Z7qGxN3Y02k+voPbtM1m
github.com/aws/aws-sdk-go-v2/service/sns v1.26.7/go.mod h1:mLFiISZfiZAqZEfPWUsZBK8gD4dYCKuKAfapV+KrIVQ=
github.com/aws/aws-sdk-go-v2/service/sqs v1.29.7 h1:tRNrFDGRm81e6nTX5Q4CFblea99eAfm0dxXazGpLceU=
github.com/aws/aws-sdk-go-v2/service/sqs v1.29.7/go.mod h1:8GWUDux5Z2h6z2efAtr54RdHXtLm8sq7Rg85ZNY/CZM=
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.2 h1:JcvYXGYiu7ME17irbW6kvWno2LG5i29Ci0UZyWX0IOs=
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.2/go.mod h1:loBAHYxz7JyucJvq4xuW9vunu8iCzjNYfSrQg2QEczA=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10/go.mod h1:ouy2P4z6sJN70fR3ka3wD3Ro3KezSxU6eKGQI2+2fjI=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 h1:mnbuWHOcM70/OFUlZZ5rcdfA8PflGXXiefU/O+1S3+8=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3/go.mod h1:5HFu51Elk+4oRBZVxmHrSds5jFXmFj8C3w7DVF2gnrs=
Expand Down
2 changes: 1 addition & 1 deletion integrations/event-handler/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.3 // indirect
github.com/aws/aws-sdk-go-v2/service/rds v1.66.2 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.51.4 // indirect
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.5 // indirect
Expand Down Expand Up @@ -246,7 +247,6 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sashabaranov/go-openai v1.17.10 // indirect
github.com/scim2/filter-parser/v2 v2.2.0 // indirect
github.com/sethvargo/go-diceware v0.3.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sijms/go-ora/v2 v2.7.9 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions integrations/event-handler/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ github.com/aws/aws-sdk-go-v2/service/rds v1.66.2 h1:2DwZGc7FM7swBDbkPlOhRJ5WolNY
github.com/aws/aws-sdk-go-v2/service/rds v1.66.2/go.mod h1:N/ijzTwR4cOG2P8Kvos/QOCetpDTtconhvDOheqnrTw=
github.com/aws/aws-sdk-go-v2/service/s3 v1.51.4 h1:lW5xUzOPGAMY7HPuNF4FdyBwRc3UJ/e8KsapbesVeNU=
github.com/aws/aws-sdk-go-v2/service/s3 v1.51.4/go.mod h1:MGTaf3x/+z7ZGugCGvepnx2DS6+caCYYqKhzVoLNYPk=
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.2 h1:JcvYXGYiu7ME17irbW6kvWno2LG5i29Ci0UZyWX0IOs=
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.2/go.mod h1:loBAHYxz7JyucJvq4xuW9vunu8iCzjNYfSrQg2QEczA=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 h1:mnbuWHOcM70/OFUlZZ5rcdfA8PflGXXiefU/O+1S3+8=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3/go.mod h1:5HFu51Elk+4oRBZVxmHrSds5jFXmFj8C3w7DVF2gnrs=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3 h1:uLq0BKatTmDzWa/Nu4WO0M1AaQDaPpwTKAeByEc6WFM=
Expand Down Expand Up @@ -835,8 +837,6 @@ github.com/scim2/filter-parser/v2 v2.2.0/go.mod h1:jWnkDToqX/Y0ugz0P5VvpVEUKcWcy
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sethvargo/go-diceware v0.3.0 h1:UVVEfmN/uF50JfWAN7nbY6CiAlp5xeSx+5U0lWKkMCQ=
github.com/sethvargo/go-diceware v0.3.0/go.mod h1:lH5Q/oSPMivseNdhMERAC7Ti5oOPqsaVddU1BcN1CY0=
github.com/sethvargo/go-limiter v0.7.2 h1:FgC4N7RMpV5gMrUdda15FaFTkQ/L4fEqM7seXMs4oO8=
github.com/sethvargo/go-limiter v0.7.2/go.mod h1:C0kbSFbiriE5k2FFOe18M1YZbAR2Fiwf72uGu0CXCcU=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
Expand Down
2 changes: 1 addition & 1 deletion integrations/terraform/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.51.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sns v1.26.7 // indirect
github.com/aws/aws-sdk-go-v2/service/sqs v1.29.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.5 // indirect
Expand Down Expand Up @@ -336,7 +337,6 @@ require (
github.com/segmentio/asm v1.2.0 // indirect
github.com/segmentio/encoding v0.3.5 // indirect
github.com/segmentio/parquet-go v0.0.0-20230622230624-510764ae9e80 // indirect
github.com/sethvargo/go-diceware v0.3.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 // indirect
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07 // indirect
Expand Down
4 changes: 2 additions & 2 deletions integrations/terraform/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ github.com/aws/aws-sdk-go-v2/service/sns v1.26.7 h1:DylmW2c1Z7qGxN3Y02k+voPbtM1m
github.com/aws/aws-sdk-go-v2/service/sns v1.26.7/go.mod h1:mLFiISZfiZAqZEfPWUsZBK8gD4dYCKuKAfapV+KrIVQ=
github.com/aws/aws-sdk-go-v2/service/sqs v1.29.7 h1:tRNrFDGRm81e6nTX5Q4CFblea99eAfm0dxXazGpLceU=
github.com/aws/aws-sdk-go-v2/service/sqs v1.29.7/go.mod h1:8GWUDux5Z2h6z2efAtr54RdHXtLm8sq7Rg85ZNY/CZM=
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.2 h1:JcvYXGYiu7ME17irbW6kvWno2LG5i29Ci0UZyWX0IOs=
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.2/go.mod h1:loBAHYxz7JyucJvq4xuW9vunu8iCzjNYfSrQg2QEczA=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10/go.mod h1:ouy2P4z6sJN70fR3ka3wD3Ro3KezSxU6eKGQI2+2fjI=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 h1:mnbuWHOcM70/OFUlZZ5rcdfA8PflGXXiefU/O+1S3+8=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3/go.mod h1:5HFu51Elk+4oRBZVxmHrSds5jFXmFj8C3w7DVF2gnrs=
Expand Down Expand Up @@ -1278,8 +1280,6 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sethvargo/go-diceware v0.3.0 h1:UVVEfmN/uF50JfWAN7nbY6CiAlp5xeSx+5U0lWKkMCQ=
github.com/sethvargo/go-diceware v0.3.0/go.mod h1:lH5Q/oSPMivseNdhMERAC7Ti5oOPqsaVddU1BcN1CY0=
github.com/shabbyrobe/gocovmerge v0.0.0-20190829150210-3e036491d500 h1:WnNuhiq+FOY3jNj6JXFT+eLN3CQ/oPIsDPRanvwsmbI=
github.com/shabbyrobe/gocovmerge v0.0.0-20190829150210-3e036491d500/go.mod h1:+njLrG5wSeoG4Ds61rFgEzKvenR2UHbjMoDHsczxly0=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
Expand Down
14 changes: 14 additions & 0 deletions lib/cloud/aws/policy_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ func StatementForEC2InstanceConnectEndpoint() *Statement {
}
}

// StatementForEC2SSMAutoDiscover returns the required statement to enable EC2 Auto Discover using SSM.
func StatementForEC2SSMAutoDiscover() *Statement {
return &Statement{
Effect: EffectAllow,
Actions: []string{
"ec2:DescribeInstances",
"ssm:DescribeInstanceInformation",
"ssm:GetCommandInvocation",
"ssm:SendCommand",
},
Resources: allResources,
}
}

// StatementForAWSAppAccess returns the statement that allows AWS App Access.
// Only IAM Roles with `teleport.dev/integration: Allowed` Tag can be used.
func StatementForAWSAppAccess() *Statement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
"github.com/google/uuid"
)

// EC2DiscoverySSMDocument receives the proxy address and returns an SSM Document.
// This document downloads and runs a Teleport installer.
// Requires the proxy endpoint URL, example: https://tenant.teleport.sh
func EC2DiscoverySSMDocument(proxy string) string {
randString := uuid.NewString() // Secure random so the filename can not be guessed to avoid possible script injection

Expand Down
20 changes: 20 additions & 0 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ type CommandLineFlags struct {
// `teleport integration configure aws-app-access-iam` command
IntegrationConfAWSAppAccessIAMArguments IntegrationConfAWSAppAccessIAM

// IntegrationConfEC2SSMIAMArguments contains the arguments of
// `teleport integration configure ec2-ssm-iam` command
IntegrationConfEC2SSMIAMArguments IntegrationConfEC2SSMIAM

// IntegrationConfEKSIAMArguments contains the arguments of
// `teleport integration configure eks-iam` command
IntegrationConfEKSIAMArguments IntegrationConfEKSIAM
Expand Down Expand Up @@ -281,6 +285,22 @@ type IntegrationConfAWSAppAccessIAM struct {
RoleName string
}

// IntegrationConfEC2SSMIAM contains the arguments of
// `teleport integration configure ec2-ssm-iam` command
type IntegrationConfEC2SSMIAM struct {
// RoleName is the AWS Role associated with the Integration
RoleName string
// Region is the AWS Region used to set up the client.
Region string
// SSMDocumentName is the SSM Document to be created that will run the installer script.
SSMDocumentName string
// ProxyPublicURL is Proxy's Public URL.
// This is used fetch the installer script.
// No trailing / is expected.
// Eg https://tenant.teleport.sh
ProxyPublicURL string
}

// IntegrationConfEKSIAM contains the arguments of
// `teleport integration configure eks-iam` command
type IntegrationConfEKSIAM struct {
Expand Down
14 changes: 2 additions & 12 deletions lib/configurators/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@ var (
"kms:GenerateDataKey",
"kms:Decrypt",
}
// ec2Actions is a list of actions used for EC2 auto-discovery
ec2Actions = []string{
"ec2:DescribeInstances",
"ssm:GetCommandInvocation",
"ssm:SendCommand",
}
// stsActions is a list of actions used for assuming an AWS role.
stsActions = []string{
"sts:AssumeRole",
Expand Down Expand Up @@ -799,7 +793,7 @@ func buildSSMDocumentCreators(ssm map[string]ssmiface.SSMAPI, targetCfg targetCo
ssmCreator := awsSSMDocumentCreator{
ssm: ssm[region],
Name: matcher.SSM.DocumentName,
Contents: EC2DiscoverySSMDocument(proxyAddr),
Contents: awslib.EC2DiscoverySSMDocument(proxyAddr),
}
creators = append(creators, &ssmCreator)
}
Expand Down Expand Up @@ -1009,11 +1003,7 @@ func buildIAMEditStatements(target awslib.Identity) ([]*awslib.Statement, error)
// EC2 instance auto-discovery.
func buildEC2AutoDiscoveryStatements() []*awslib.Statement {
return []*awslib.Statement{
{
Effect: awslib.EffectAllow,
Actions: ec2Actions,
Resources: []string{"*"},
},
awslib.StatementForEC2SSMAutoDiscover(),
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/configurators/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ func TestAWSIAMDocuments(t *testing.T) {
Effect: "Allow",
Actions: []string{
"ec2:DescribeInstances",
"ssm:DescribeInstanceInformation",
"ssm:GetCommandInvocation",
"ssm:SendCommand"},
Resources: []string{"*"},
Expand All @@ -592,6 +593,7 @@ func TestAWSIAMDocuments(t *testing.T) {
Effect: "Allow",
Actions: []string{
"ec2:DescribeInstances",
"ssm:DescribeInstanceInformation",
"ssm:GetCommandInvocation",
"ssm:SendCommand"},
Resources: []string{"*"},
Expand Down Expand Up @@ -1837,7 +1839,7 @@ func TestAWSDocumentConfigurator(t *testing.T) {
"eu-central-1": &SSMMock{
t: t,
expectedInput: &ssm.CreateDocumentInput{
Content: aws.String(EC2DiscoverySSMDocument("https://proxy.example.org:443")),
Content: aws.String(awslib.EC2DiscoverySSMDocument("https://proxy.example.org:443")),
DocumentType: aws.String("Command"),
DocumentFormat: aws.String("YAML"),
Name: aws.String("document"),
Expand Down
183 changes: 183 additions & 0 deletions lib/integrations/awsoidc/ec2_ssm_iam_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package awsoidc

import (
"context"
"errors"
"log/slog"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/ssm"
ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types"
"github.com/gravitational/trace"

awslib "github.com/gravitational/teleport/lib/cloud/aws"
)

const (
// defaultPolicyNameForEC2SSM is the default name for the Inline Policy added to the IntegrationRole.
defaultPolicyNameForEC2SSM = "EC2DiscoverWithSSM"
)

// EC2SSMIAMConfigureRequest is a request to configure the required Policies to use the EC2 Auto Discover with SSM.
type EC2SSMIAMConfigureRequest struct {
// Region is the AWS Region.
// Used to set up the AWS SDK Client.
Region string

// IntegrationRole is the Integration's AWS Role used to set up Teleport as an OIDC IdP.
IntegrationRole string

// IntegrationRoleEC2SSMPolicy is the Policy Name that is created to allow access to call AWS APIs.
// Defaults to EC2DiscoverWithSSM.
IntegrationRoleEC2SSMPolicy string

// SSMDocumentName is the SSM Document to be created.
// This document calls the installer scripts in the target host.
SSMDocumentName string

// ProxyPublicURL is Proxy's Public URL.
// This is used fetch the installer script.
// No trailing / is expected.
// Eg https://tenant.teleport.sh
ProxyPublicURL string
}

// CheckAndSetDefaults ensures the required fields are present.
func (r *EC2SSMIAMConfigureRequest) CheckAndSetDefaults() error {
if r.Region == "" {
return trace.BadParameter("region is required")
}

if r.IntegrationRole == "" {
return trace.BadParameter("integration role is required")
}

if r.IntegrationRoleEC2SSMPolicy == "" {
r.IntegrationRoleEC2SSMPolicy = defaultPolicyNameForEC2SSM
}

if r.SSMDocumentName == "" {
return trace.BadParameter("ssm document name is required")
}

if r.ProxyPublicURL == "" {
return trace.BadParameter("proxy public url is required")
}

return nil
}

// EC2SSMConfigureClient describes the required methods to create the IAM Policies and SSM Document required for installing Teleport in EC2 instances.
type EC2SSMConfigureClient interface {
// PutRolePolicy creates or replaces a Policy by its name in a IAM Role.
PutRolePolicy(ctx context.Context, params *iam.PutRolePolicyInput, optFns ...func(*iam.Options)) (*iam.PutRolePolicyOutput, error)

// CreateDocument creates a Amazon Web Services Systems Manager (SSM document).
CreateDocument(ctx context.Context, params *ssm.CreateDocumentInput, optFns ...func(*ssm.Options)) (*ssm.CreateDocumentOutput, error)
}

type defaultEC2SSMConfigureClient struct {
*iam.Client
ssmClient *ssm.Client
}

// CreateDocument creates a Amazon Web Services Systems Manager (SSM document).
func (d *defaultEC2SSMConfigureClient) CreateDocument(ctx context.Context, params *ssm.CreateDocumentInput, optFns ...func(*ssm.Options)) (*ssm.CreateDocumentOutput, error) {
return d.ssmClient.CreateDocument(ctx, params, optFns...)
}

// NewEC2SSMConfigureClient creates a new EC2SSMConfigureClient.
func NewEC2SSMConfigureClient(ctx context.Context, region string) (EC2SSMConfigureClient, error) {
if region == "" {
return nil, trace.BadParameter("region is required")
}

cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region))
if err != nil {
return nil, trace.Wrap(err)
}

return &defaultEC2SSMConfigureClient{
Client: iam.NewFromConfig(cfg),
ssmClient: ssm.NewFromConfig(cfg),
}, nil
}

// ConfigureEC2SSM creates the required resources in AWS to enable EC2 Auto Discover using script mode..
// It creates an embedded policy with the following permissions:
//
// Action: List EC2 instances where teleport is going to be installed.
// - ec2:DescribeInstances
//
// Action: Run a command and get its output.
// - ssm:SendCommand
// - ssm:GetCommandInvocation
//
// Besides setting up the required IAM policies, this method also adds the SSM Document.
// This SSM Document downloads and runs the Teleport Installer Script, which installs teleport in the target EC2 instance.
func ConfigureEC2SSM(ctx context.Context, clt EC2SSMConfigureClient, req EC2SSMIAMConfigureRequest) error {
if err := req.CheckAndSetDefaults(); err != nil {
return trace.Wrap(err)
}

ec2ICEPolicyDocument, err := awslib.NewPolicyDocument(
awslib.StatementForEC2SSMAutoDiscover(),
).Marshal()
if err != nil {
return trace.Wrap(err)
}

_, err = clt.PutRolePolicy(ctx, &iam.PutRolePolicyInput{
PolicyName: &req.IntegrationRoleEC2SSMPolicy,
RoleName: &req.IntegrationRole,
PolicyDocument: &ec2ICEPolicyDocument,
})
if err != nil {
if trace.IsNotFound(awslib.ConvertIAMv2Error(err)) {
return trace.NotFound("role %q not found", req.IntegrationRole)
}
return trace.Wrap(err)
}

slog.InfoContext(ctx, "IntegrationRole: IAM Policy added to Role", "policy", req.IntegrationRoleEC2SSMPolicy, "role", req.IntegrationRole)

_, err = clt.CreateDocument(ctx, &ssm.CreateDocumentInput{
Name: aws.String(req.SSMDocumentName),
DocumentType: ssmtypes.DocumentTypeCommand,
DocumentFormat: ssmtypes.DocumentFormatYaml,
Content: aws.String(awslib.EC2DiscoverySSMDocument(req.ProxyPublicURL)),
})
if err != nil {
var docAlreadyExistsError *ssmtypes.DocumentAlreadyExists
if errors.As(err, &docAlreadyExistsError) {
slog.InfoContext(ctx, "SSM Document already exists", "name", req.SSMDocumentName)
return nil
}

return trace.Wrap(err)
}

slog.InfoContext(ctx, "SSM Document created", "name", req.SSMDocumentName)

return nil
}
Loading

0 comments on commit 9018a36

Please sign in to comment.