-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration configure commands prompt for changes
This applies to the following "teleport integration configure" subcommands: * deployservice-iam * eice-iam * ec2-ssm-iam * aws-app-access-iam * eks-iam * access-graph * listdatabases-iam These commands will now describe the actions they will take, the resources that will be created/configured, and will by default prompt the user to confirm the changes. Confirmation prompt can be skipped by passing the new --confirm flag. The confirmation prompt is enabled by default because the most common case, if not the only case, where a user runs these commands is via an opaque "bash -c $(curl ...)" script generated by a web UI enrollment wizard.
- Loading branch information
1 parent
7b0e857
commit 0fe3bdb
Showing
30 changed files
with
1,001 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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 awsactions | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/ssm" | ||
ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types" | ||
"github.com/gravitational/trace" | ||
|
||
"github.com/gravitational/teleport/lib/cloud/provisioning" | ||
"github.com/gravitational/teleport/lib/integrations/awsoidc/tags" | ||
) | ||
|
||
// DocumentCreator can create an AWS SSM document. | ||
type DocumentCreator interface { | ||
// CreateDocument creates an AWS SSM document. | ||
CreateDocument(ctx context.Context, params *ssm.CreateDocumentInput, optFns ...func(*ssm.Options)) (*ssm.CreateDocumentOutput, error) | ||
} | ||
|
||
// CreateDocument wraps a [DocumentCreator] in a [provisioning.Action] that | ||
// creates an SSM document when invoked. | ||
func CreateDocument( | ||
clt DocumentCreator, | ||
name string, | ||
content string, | ||
docType ssmtypes.DocumentType, | ||
docFormat ssmtypes.DocumentFormat, | ||
tags tags.AWSTags, | ||
) (*provisioning.Action, error) { | ||
|
||
input := &ssm.CreateDocumentInput{ | ||
Name: aws.String(name), | ||
DocumentType: docType, | ||
DocumentFormat: docFormat, | ||
Content: aws.String(content), | ||
Tags: tags.ToSSMTags(), | ||
} | ||
details, err := formatDetails(input) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
|
||
config := provisioning.ActionConfig{ | ||
Name: "CreateDocument", | ||
Summary: fmt.Sprintf("Create an AWS Systems Manager (SSM) %s document %q", docType, name), | ||
Details: details, | ||
RunnerFn: func(ctx context.Context) error { | ||
_, err = clt.CreateDocument(ctx, input) | ||
if err != nil { | ||
var docAlreadyExistsError *ssmtypes.DocumentAlreadyExists | ||
if errors.As(err, &docAlreadyExistsError) { | ||
slog.InfoContext(ctx, "SSM document already exists", "name", name) | ||
return nil | ||
} | ||
|
||
return trace.Wrap(err) | ||
} | ||
|
||
slog.InfoContext(ctx, "SSM document created", "name", name) | ||
return nil | ||
}, | ||
} | ||
action, err := provisioning.NewAction(config) | ||
return action, trace.Wrap(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* 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 awsactions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/iam" | ||
"github.com/gravitational/trace" | ||
|
||
awslib "github.com/gravitational/teleport/lib/cloud/aws" | ||
"github.com/gravitational/teleport/lib/cloud/provisioning" | ||
) | ||
|
||
// RolePolicyPutter can upsert an IAM inline role policy. | ||
type RolePolicyPutter interface { | ||
// PutRolePolicy creates or replaces a Policy by its name in a IAM Role. | ||
PutRolePolicy(context.Context, *iam.PutRolePolicyInput, ...func(*iam.Options)) (*iam.PutRolePolicyOutput, error) | ||
} | ||
|
||
// PutRolePolicy wraps a [RolePolicyPutter] in a [provisioning.Action] that | ||
// upserts an inline IAM policy when invoked. | ||
func PutRolePolicy( | ||
clt RolePolicyPutter, | ||
policyName string, | ||
roleName string, | ||
policy *awslib.PolicyDocument, | ||
) (*provisioning.Action, error) { | ||
|
||
policyJSON, err := policy.Marshal() | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
input := &iam.PutRolePolicyInput{ | ||
PolicyName: &policyName, | ||
RoleName: &roleName, | ||
PolicyDocument: &policyJSON, | ||
} | ||
type putRolePolicyInput struct { | ||
// PolicyDocument shadows the input's field of the same name | ||
// to marshal the trust policy doc as unescaped JSON. | ||
PolicyDocument *awslib.PolicyDocument | ||
*iam.PutRolePolicyInput | ||
} | ||
details, err := formatDetails(putRolePolicyInput{ | ||
PolicyDocument: policy, | ||
PutRolePolicyInput: input, | ||
}) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
|
||
config := provisioning.ActionConfig{ | ||
Name: "PutRolePolicy", | ||
Summary: fmt.Sprintf("Attach an inline IAM policy named %q to IAM role %q", | ||
policyName, | ||
roleName, | ||
), | ||
Details: details, | ||
RunnerFn: func(ctx context.Context) error { | ||
_, err = clt.PutRolePolicy(ctx, input) | ||
if err != nil { | ||
if trace.IsNotFound(awslib.ConvertIAMv2Error(err)) { | ||
return trace.NotFound("role %q not found.", roleName) | ||
} | ||
return trace.Wrap(err) | ||
} | ||
|
||
slog.InfoContext(ctx, "Added inline policy to IAM role", | ||
"policy", policyName, | ||
"role", roleName, | ||
) | ||
return nil | ||
}, | ||
} | ||
action, err := provisioning.NewAction(config) | ||
return action, trace.Wrap(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.