Skip to content
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: OB-37376 merge cf stacks for push and pull by adding poller rol… #342

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion apps/stack/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ Metadata:
default: CloudWatch Metrics
Parameters:
- MetricStreamFilterUri
- Label:
default: Cloudwatch Metrics Poller Role
Parameters:
- ObserveAwsAccountId
- DatastreamIds
- Label:
default: Forwarder Options
Parameters:
Expand Down Expand Up @@ -150,6 +155,18 @@ Parameters:
Description: >-
The token used to retrieve metric configuration.
Default: ''
ObserveAwsAccountId:
Type: String
Description: Observe AWS Account ID which will be allowed to assume role.
AllowedPattern: '\d*'
Default: ''
DatastreamIds:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this check going to happen on the poller side? its not happening in the sam app side right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you referring to the validity of the ObserveAwsAccountId? I thought this would happen based on the frontend passing in correct input. I'll hardcode AllowedActions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean why do they need to know datastreamIds at all? The whole point is to just add an iam policy and allow our poller iam role to assume it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because of how AWS recommends allowing other accounts to access your resources: see here. It seems that it is possible to do this process without having an external id, but it is not recommended. This is also how the poller works currently - we pass in the datastreamIds (terraform) and then we use it to assume roles. We take it as input here and use it to get credentials we can use in our polling. So the stack here is just checking that the request is coming from our backend.

Type: CommaDelimitedList
Description: Datastream IDs where data will be ingested to.
This ensures Observe cannot assume this role outside
of this context.
AllowedPattern: \d*
Default: ''
SourceBucketNames:
Type: CommaDelimitedList
Description: >-
Expand Down Expand Up @@ -214,7 +231,10 @@ Conditions:
- !Equals
- !Ref DatasourceID
- ""

EnableMetricsPollerRole: !Not
- !Equals
- !Ref ObserveAwsAccountId
- ""
Resources:
Topic:
Type: "AWS::SNS::Topic"
Expand Down Expand Up @@ -378,6 +398,22 @@ Resources:
- UseStackName
- !Sub "${AWS::StackName}-MetricStream"
- !Sub "${NameOverride}-MetricStream"
MetricsPollerRole:
Type: AWS::Serverless::Application
Copy link
Contributor

@obs-gh-alexlew obs-gh-alexlew Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this "application" is just a role and a policy? and you've already added that to the stack?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by already - the nested stack externalrole is only deployed if ObserveAwsAccountId is provided. Yes, it is just a role and policy - check out externalrole/template.yaml. Note that this nested stack existed in the aws-sam-apps repo before I made this commit. My change was that I made it such that the externalrole stack was conditionally nested under the main stack for push based, if ObserveAwsAccountId is provided. I didn't have to change externalrole.yaml at all.

Condition: EnableMetricsPollerRole
Properties:
Location: ../externalrole/template.yaml
NotificationARNs:
- !Ref Topic
Parameters:
ObserveAwsAccountId: !Ref ObserveAwsAccountId
AllowedActions: >-
cloudwatch:GetMetricData,cloudwatch:ListMetrics,tag:GetResources
DatastreamIds: !Join [",", !Ref DatastreamIds]
NameOverride: !If
- UseStackName
- !Sub "${AWS::StackName}-MetricsPollerRole"
- !Sub "${NameOverride}-MetricsPollerRole"
Outputs:
BucketName:
Description: >-
Expand Down