-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support permission init for control plane management volume #104
Merged
Merged
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
9ffca38
Support permission init
tuteng 41e6788
Support s3 bucket access
tuteng a2b4989
Fixed example
tuteng a5929c5
Fixed volume module
tuteng 559eea4
Fixed oidc provider
tuteng f4dbc20
Format code
tuteng 7d46c0d
Fixed test
tuteng 1778f65
Fixed comment
tuteng 737a5d5
Merge branch 'feature/support-init-sn-volume-access-bak' into feature…
tuteng 56ab268
Fixed providers
tuteng be99962
Removed no used module
tuteng 9c93682
Fixed volume access
tuteng 144090e
Fixed module
tuteng 3450f86
Update example
tuteng 548adf1
Removed no used file
tuteng 6dac346
Fixed comment
tuteng c26dca9
Fixed comment
tuteng 9429ef5
Fixed check
tuteng f05e13a
Fixed comment
tuteng 1169a4e
Add new field
tuteng 53159bc
Fixed comment
tuteng 89841d6
Revert config
tuteng 7e1708a
Fixed condition check
tuteng b97de86
Fixed comment
tuteng ab5c8a4
Fixed comment
tuteng a59d6e3
Fixed main file
tuteng c849dc1
Fixed assume conditions
tuteng a9e1dab
Fixed comment
tuteng 58db995
Fixed comment
tuteng 4fa0eb4
Fixed comment
tuteng 4dfb5a6
Fixed cmment
tuteng a4f1413
Format code
tuteng 0000db7
Add distinc func
tuteng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,17 @@ | ||
provider "aws" { | ||
region = "us-west-2" | ||
} | ||
|
||
module "sn_managed_cloud" { | ||
source = "../../modules/aws/volume-access" | ||
|
||
external_id = "max" | ||
bucket = "test-ursa-storage" | ||
path = "ursa" | ||
|
||
oidc_providers = [ | ||
] | ||
|
||
streamnative_vendor_access_role_arns = [ | ||
] | ||
} |
35 changes: 35 additions & 0 deletions
35
modules/aws/volume-access/files/sn_volume_s3_bucket.json.tpl
maxsxu marked this conversation as resolved.
Show resolved
Hide resolved
|
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,35 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:ListBucket" | ||
], | ||
"Resource": [ | ||
"arn:aws:s3:::${bucket}" | ||
] | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:PutObject", | ||
"s3:GetObject", | ||
"s3:DeleteObject" | ||
], | ||
"Resource": [ | ||
"arn:aws:s3:::${bucket}/${path}/*" | ||
] | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:PutLifecycleConfiguration", | ||
"s3:GetLifecycleConfiguration" | ||
], | ||
"Resource": [ | ||
"arn:aws:s3:::${bucket}/${path}" | ||
] | ||
} | ||
] | ||
} |
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,112 @@ | ||
data "aws_caller_identity" "current" {} | ||
locals { | ||
account_id = data.aws_caller_identity.current.account_id | ||
external_id = (var.external_id != "" ? [{ test : "StringEquals", variable : "sts:ExternalId", values : [var.external_id] }] : []) | ||
assume_conditions = concat(local.external_id, local.source_identity, local.principal_check, local.vendor_federation) | ||
support_assume_conditions = concat(local.external_id, local.source_identity) | ||
source_identity = (length(var.source_identities) > 0 ? [{ test : var.source_identity_test, variable : "sts:SourceIdentity", values : var.source_identities }] : []) | ||
maxsxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
oidc_providers = distinct(concat(var.oidc_providers, local.default_oidc_providers)) | ||
principal_check = (length(var.streamnative_principal_ids) > 0 ? [{ test : "StringLike", variable : "aws:PrincipalArn", values : var.streamnative_principal_ids }] : []) | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tag_set = merge({ Vendor = "StreamNative", Module = "StreamNative Volume", SNVersion = var.sn_policy_version }, var.tags) | ||
vendor_federation = (var.enforce_vendor_federation ? [{ test : "StringLike", variable : "aws:FederatedProvider", values : ["accounts.google.com"] }] : []) | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Add streamnative default eks oidc provider | ||
default_oidc_providers = compact([ | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
]) | ||
conditions = [ | ||
for value in local.oidc_providers : | ||
[ | ||
{ | ||
provider : "${value}", | ||
test : "StringEquals", | ||
variable : "${value}:aud", | ||
values : ["sts.amazonaws.com"] | ||
}, | ||
{ | ||
provider : "${value}", | ||
test : "StringEquals", | ||
variable : "${value}:sub", | ||
values : [format("system:serviceaccount:%s:*", var.external_id)] | ||
} | ||
] | ||
] | ||
} | ||
|
||
resource "aws_iam_openid_connect_provider" "streamnative_oidc_providers" { | ||
maxsxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
count = length(local.oidc_providers) | ||
url = "https://${var.oidc_providers[count.index]}" | ||
client_id_list = ["sts.amazonaws.com"] | ||
tags = local.tag_set | ||
} | ||
|
||
data "aws_iam_policy_document" "streamnative_management_access" { | ||
statement { | ||
sid = "AllowStreamNativeControlPlaneAccess" | ||
effect = "Allow" | ||
actions = ["sts:AssumeRole"] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = var.streamnative_vendor_access_role_arns | ||
} | ||
dynamic "condition" { | ||
for_each = local.assume_conditions | ||
content { | ||
test = condition.value["test"] | ||
values = condition.value["values"] | ||
variable = condition.value["variable"] | ||
} | ||
} | ||
} | ||
|
||
dynamic "statement" { | ||
maxsxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for_each = local.conditions | ||
maxsxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
content { | ||
maxsxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
effect = "Allow" | ||
actions = ["sts:AssumeRoleWithWebIdentity"] | ||
|
||
principals { | ||
type = "Federated" | ||
identifiers = [for provider in local.oidc_providers : "arn:aws:iam::${local.account_id}:oidc-provider/${provider}" if "${provider}" == statement.value[0].provider] | ||
} | ||
|
||
dynamic "condition" { | ||
for_each = toset(statement.value) | ||
maxsxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
content { | ||
test = condition.value["test"] | ||
values = condition.value["values"] | ||
variable = condition.value["variable"] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
###### | ||
#-- Create the IAM role for the the StreamNative Cloud data access to s3 bucket | ||
###### | ||
resource "aws_iam_policy" "access_bucket_role" { | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name = "sn-${var.external_id}-${var.bucket}-${var.path}" | ||
description = "This policy sets the limits for the access s3 bucket for StreamNative's vendor access." | ||
path = "/StreamNative/" | ||
policy = templatefile("${path.module}/files/sn_volume_s3_bucket.json.tpl", | ||
{ | ||
bucket = var.bucket | ||
path = var.path | ||
}) | ||
tags = local.tag_set | ||
} | ||
|
||
resource "aws_iam_role" "access_bucket_role" { | ||
name = "sn-${var.external_id}-${var.bucket}-${var.path}" | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description = "This role is used by StreamNative for the access s3 bucket." | ||
assume_role_policy = data.aws_iam_policy_document.streamnative_management_access.json | ||
path = "/StreamNative/" | ||
tags = local.tag_set | ||
max_session_duration = 43200 | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "access_bucket_role" { | ||
policy_arn = aws_iam_policy.access_bucket_role.arn | ||
role = aws_iam_role.access_bucket_role.name | ||
} |
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,75 @@ | ||
variable "sn_policy_version" { | ||
description = "The value of SNVersion tag" | ||
default = "3.16.1" # {{ x-release-please-version }} | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
maxsxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default = "*" | ||
description = "The AWS region where your instance of StreamNative Cloud is deployed. Defaults to all regions \"*\"" | ||
type = string | ||
} | ||
|
||
variable "streamnative_vendor_access_role_arns" { | ||
default = ["arn:aws:iam::311022431024:role/cloud-manager"] | ||
description = "This role for access customer s3 bucket on control plane." | ||
type = list(string) | ||
} | ||
|
||
variable "additional_federated_identifiers" { | ||
default = [] | ||
description = "This federated identified list for access customer s3 bucket on data plane." | ||
type = list(string) | ||
} | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
variable "streamnative_principal_ids" { | ||
default = [] | ||
description = "When set, this applies an additional check for certain StreamNative principals to futher restrict access to which services / users can access an account." | ||
type = list(string) | ||
} | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
variable "source_identities" { | ||
default = [] | ||
description = "Place an additional constraint on source identity, disabled by default and only to be used if specified by StreamNative" | ||
type = list(any) | ||
} | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
variable "source_identity_test" { | ||
default = "ForAnyValue:StringLike" | ||
description = "The test to use for source identity" | ||
type = string | ||
} | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
variable "external_id" { | ||
default = "" | ||
description = "A external ID that correspond to your Organization within StreamNative Cloud, used for all STS assume role calls to the IAM roles created by the module. This will be the organization ID in the StreamNative console, e.g. \"o-xhopj\"." | ||
type = string | ||
} | ||
|
||
variable "tags" { | ||
default = {} | ||
description = "Extra tags to apply to the resources created by this module." | ||
type = map(string) | ||
} | ||
|
||
variable "enforce_vendor_federation" { | ||
default = false | ||
description = "Do not enable this unless explicitly told to do so by StreamNative. Restrict access for the streamnative_vendor_access_role_arns to only federated Google accounts. Intended to be true by default in the future." | ||
type = bool | ||
} | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
variable "bucket" { | ||
description = "User bucket name" | ||
type = string | ||
} | ||
|
||
variable "path" { | ||
description = "S3 bucket path" | ||
type = string | ||
} | ||
tuteng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
variable "oidc_providers" { | ||
default = [] | ||
description = "Your aws eks cluster OIDC Providers" | ||
maxsxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type = list(string) | ||
} |
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,10 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.30" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change it after this pr approve and merged