Skip to content

Commit

Permalink
Merge pull request #33 from joelddiaz/static-passthrough
Browse files Browse the repository at this point in the history
move to static list of passthrough creds
  • Loading branch information
openshift-merge-robot committed Feb 22, 2019
2 parents 484bf2b + 083772f commit 01bbf37
Show file tree
Hide file tree
Showing 32 changed files with 66 additions and 2,197 deletions.
11 changes: 0 additions & 11 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
required = [
"github.com/aws/aws-sdk-go",
"github.com/emicklei/go-restful",
"github.com/jteeuwen/go-bindata",
"github.com/onsi/ginkgo", # for test framework
"github.com/onsi/gomega", # for test matchers
"github.com/stretchr/testify/assert",
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ vet:
# Generate code
generate:
go generate ./pkg/... ./cmd/...
# generate static assets
hack/update-bindata.sh

# Build the image with buildah
.PHONY: buildah-build
Expand Down
20 changes: 0 additions & 20 deletions hack/update-bindata.sh

This file was deleted.

This file was deleted.

This file was deleted.

106 changes: 0 additions & 106 deletions pkg/controller/assets/bindata.go

This file was deleted.

90 changes: 66 additions & 24 deletions pkg/controller/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

ccv1beta1 "github.com/openshift/cloud-credential-operator/pkg/apis/cloudcredential/v1beta1"
ccaws "github.com/openshift/cloud-credential-operator/pkg/aws"
"github.com/openshift/cloud-credential-operator/pkg/controller/assets"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iam"
Expand All @@ -19,7 +18,7 @@ import (
// credMintingActions is a list of AWS verbs needed to run in the mode where the
// cloud-credential-operator can mint new creds to satisfy CredentialRequest CRDs
var (
CredMintingActions = []string{
credMintingActions = []string{
"iam:CreateAccessKey",
"iam:CreateUser",
"iam:DeleteAccessKey",
Expand All @@ -33,6 +32,66 @@ var (
"iam:SimulatePrincipalPolicy", // needed so we can verify the above list of course
}

credPassthroughActions = []string{
// so we can query whether we have the below list of creds
"iam:GetUser",
"iam:SimulatePrincipalPolicy",

// openshift-ingress
"elasticloadbalancing:DescribeLoadBalancers",
"route53:ListHostedZones",
"route53:ChangeResourceRecordSets",
"tag:GetResources",

// openshift-image-registry
"s3:CreateBucket",
"s3:DeleteBucket",
"s3:PutBucketTagging",
"s3:GetBucketTagging",
"s3:PutEncryptionConfiguration",
"s3:GetEncryptionConfiguration",
"s3:PutLifecycleConfiguration",
"s3:GetLifecycleConfiguration",
"s3:GetBucketLocation",
"s3:ListBucket",
"s3:HeadBucket",
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:ListBucketMultipartUploads",
"s3:AbortMultipartUpload",

// openshift-cluster-api
"ec2:DescribeImages",
"ec2:DescribeVpcs",
"ec2:DescribeSubnets",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeSecurityGroups",
"ec2:RunInstances",
"ec2:DescribeInstances",
"ec2:TerminateInstances",
"elasticloadbalancing:RegisterInstancesWithLoadBalancer",
"elasticloadbalancing:DescribeLoadBalancers",
"elasticloadbalancing:DescribeTargetGroups",
"elasticloadbalancing:RegisterTargets",
"ec2:DescribeVpcs",
"ec2:DescribeSubnets",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeSecurityGroups",
"ec2:RunInstances",
"ec2:DescribeInstances",
"ec2:TerminateInstances",
"elasticloadbalancing:RegisterInstancesWithLoadBalancer",
"elasticloadbalancing:DescribeLoadBalancers",
"elasticloadbalancing:DescribeTargetGroups",
"elasticloadbalancing:RegisterTargets",

// iam-ro
"iam:GetUser",
"iam:GetUserPolicy",
"iam:ListAccessKeys",
}

credentailRequestScheme = runtime.NewScheme()
credentialRequestCodec = serializer.NewCodecFactory(credentailRequestScheme)
)
Expand All @@ -45,7 +104,7 @@ func init() {

// CheckCloudCredCreation will see whether we have enough permissions to create new sub-creds
func CheckCloudCredCreation(awsClient ccaws.Client, logger log.FieldLogger) (bool, error) {
return CheckPermissionsAgainstActions(awsClient, CredMintingActions, logger)
return CheckPermissionsAgainstActions(awsClient, credMintingActions, logger)
}

// CheckPermissionsUsingQueryClient will use queryClient to query whether the credentials in targetClient can perform the actions
Expand Down Expand Up @@ -113,28 +172,11 @@ func CheckPermissionsAgainstActions(awsClient ccaws.Client, actionList []string,
}

// CheckCloudCredPassthrough will see if the provided creds are good enough to pass through
// to other components as-is based on the generated list of permissions needed from the static
// manifests in the repo
// to other components as-is based on the static list of permissions needed by the various
// users of CredentialsRequests
// TODO: move away from static list (to dynamic passthrough validation?)
func CheckCloudCredPassthrough(awsClient ccaws.Client, logger log.FieldLogger) (bool, error) {
statementList := []ccv1beta1.StatementEntry{}

// Read in the static assets containing all the needed CredentialRequests/permissions
assetList := assets.AssetNames()
for _, oneAsset := range assetList {
crBytes, err := assets.Asset(oneAsset)
if err != nil {
return false, fmt.Errorf("error parsing CredentialRequest object: %v", err)
}

statements, err := getCredentialRequestStatements(crBytes)
if err != nil {
return false, fmt.Errorf("error processing CredentialRequest: %v", err)
}

statementList = append(statementList, statements...)
}

return CheckPermissionsAgainstStatementList(awsClient, statementList, logger)
return CheckPermissionsAgainstActions(awsClient, credPassthroughActions, logger)
}

func readCredentialRequest(cr []byte) (*ccv1beta1.CredentialsRequest, error) {
Expand Down
Loading

0 comments on commit 01bbf37

Please sign in to comment.