Skip to content

Commit

Permalink
fixes #16 by addind max session duration to role
Browse files Browse the repository at this point in the history
  • Loading branch information
redradrat committed Nov 27, 2020
1 parent 59faed4 commit 54e6ee5
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ spec:
"StringEquals":
"blablabla": "system:serviceaccount:kube-system:aws-cluster-autoscaler"
createServiceAccount: true
maxSessionDuration: 3600
```

Resulting `ServiceAccount`:
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/role_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type RoleSpec struct {
// CreateServiceAccount triggers the creation of an annotated ServiceAccount for the created role
CreateServiceAccount bool `json:"createServiceAccount,omitempty"`

// +kubebuilder:validation:Optional
// +nullable
// MaxSessionDuration specifies the maximum duration a session with this role assumed can last
MaxSessionDuration *int64 `json:"maxSessionDuration,omitempty"`

// +kubebuilder:validation:Optional
//
// Description holds the description string for the Role
Expand Down
21 changes: 21 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

8 changes: 6 additions & 2 deletions controllers/role_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,18 @@ func (r *RoleReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
// new role instance
var ins *iam.RoleInstance
roleName := r.ResourcePrefix + role.Name
var duration int64 = 3600
if role.Spec.MaxSessionDuration != nil {
duration = *role.Spec.MaxSessionDuration
}
if role.Status.ARN != "" {
parsedArn, err := aws.ARNify(role.Status.ARN)
if err != nil {
return ctrl.Result{}, errWithStatus(&role, fmt.Errorf("ARN in Role status is not valid/parsable"), r.Status(), ctx)
}
ins = iam.NewExistingRoleInstance(roleName, role.Spec.Description, polDoc, parsedArn[len(parsedArn)-1])
ins = iam.NewExistingRoleInstance(roleName, role.Spec.Description, duration, polDoc, parsedArn[len(parsedArn)-1])
} else {
ins = iam.NewRoleInstance(roleName, role.Spec.Description, polDoc)
ins = iam.NewRoleInstance(roleName, role.Spec.Description, duration, polDoc)
}

cleanupFunc := roleCleanup(r, ctx, role)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-logr/logr v0.1.0
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.8.1
github.com/redradrat/cloud-objects v0.0.0-20200618154749-39f65bf1649f
github.com/redradrat/cloud-objects v0.0.0-20201127175728-ba53f8138637
k8s.io/api v0.17.2
k8s.io/apimachinery v0.17.2
k8s.io/client-go v0.17.2
Expand Down
Loading

0 comments on commit 54e6ee5

Please sign in to comment.