-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from vshn/fix/bucket-permissions
Deny bucket listing in iam policy
- Loading branch information
Showing
9 changed files
with
143 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package v1 | ||
|
||
import ( | ||
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// Updating returns a Ready condition where the service is updating. | ||
// Crossplane's runtine doesn't provide a pre-defined update condition for some | ||
// reason. | ||
func Updating() xpv1.Condition { | ||
return xpv1.Condition{ | ||
Type: xpv1.TypeReady, | ||
Status: corev1.ConditionFalse, | ||
Reason: "Updating", | ||
Message: "The service is being updated", | ||
LastTransitionTime: metav1.Now(), | ||
} | ||
} |
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
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,57 @@ | ||
package iamkeycontroller | ||
|
||
import ( | ||
exooapi "github.com/exoscale/egoscale/v2/oapi" | ||
"k8s.io/utils/pointer" | ||
) | ||
|
||
var ( | ||
policyAllow = exooapi.IamServicePolicyRuleActionAllow | ||
policyDeny = exooapi.IamServicePolicyRuleActionDeny | ||
) | ||
|
||
func createRole(keyName string, buckets []string) *exooapi.IamRole { | ||
|
||
policyRules := exooapi.IamServicePolicyTypeRules | ||
|
||
iamRole := &exooapi.IamRole{ | ||
Name: &keyName, | ||
Description: pointer.String("IAM Role for SOS+IAM creation, it was autogenerated by provider-exoscale"), | ||
Permissions: &[]exooapi.IamRolePermissions{ | ||
exooapi.IamRolePermissionsBypassGovernanceRetention, | ||
}, | ||
Editable: pointer.Bool(true), | ||
Policy: &exooapi.IamPolicy{ | ||
DefaultServiceStrategy: exooapi.IamPolicyDefaultServiceStrategyDeny, | ||
Services: exooapi.IamPolicy_Services{ | ||
AdditionalProperties: map[string]exooapi.IamServicePolicy{ | ||
"sos": { | ||
Type: &policyRules, | ||
Rules: &[]exooapi.IamServicePolicyRule{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
// We specifically need to deny the listing of buckets, or the customer is able to see all of them | ||
*iamRole.Policy.Services.AdditionalProperties["sos"].Rules = append(*iamRole.Policy.Services.AdditionalProperties["sos"].Rules, exooapi.IamServicePolicyRule{ | ||
Action: &policyDeny, | ||
Expression: pointer.String("operation in ['list-sos-buckets-usage', 'list-buckets']"), | ||
}) | ||
|
||
// we must first add buckets to deny list and then add the allow rule, otherwise it will not work | ||
for _, bucket := range buckets { | ||
*iamRole.Policy.Services.AdditionalProperties["sos"].Rules = append(*iamRole.Policy.Services.AdditionalProperties["sos"].Rules, exooapi.IamServicePolicyRule{ | ||
Action: &policyDeny, | ||
Expression: pointer.String("resources.bucket != " + "'" + bucket + "'"), | ||
}) | ||
} | ||
|
||
*iamRole.Policy.Services.AdditionalProperties["sos"].Rules = append(*iamRole.Policy.Services.AdditionalProperties["sos"].Rules, exooapi.IamServicePolicyRule{ | ||
Action: &policyAllow, | ||
Expression: pointer.String("true"), | ||
}) | ||
|
||
return iamRole | ||
} |
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