Skip to content

feat(cid-cmd): Add athena-profile for cross-account Athena - #1600

Open
mightymietz wants to merge 1 commit into
aws-solutions-library-samples:mainfrom
mightymietz:feature/athena-cross-account
Open

mightymietz wants to merge 1 commit into
aws-solutions-library-samples:mainfrom
mightymietz:feature/athena-cross-account

Conversation

@mightymietz

Copy link
Copy Markdown

Closes #1599

Summary

Adds an optional --athena-profile <name> so that cid-cmd can deploy dashboards in a hub-and-spoke setup: Quick runs in one account, while the CUR, the Glue database and the Athena workgroup stay in another account (for example the Data Collection account). It builds on Quick's cross-account Athena data sources (RoleArn → ConsumerAccountRoleArn).

Session Comes from Used for
Quick account --profile / default credentials QuickSight, IAM, CloudFormation, Organizations
Data account --athena-profile Athena, Glue, S3

Without --athena-profile, behaviour is unchanged, except one new safeguard: deploy / update / delete stop if the DataSource they use queries another account.

Changes

cid/common.py

  • aws_login() opens a second session from --athena-profile (same Region, partition checked against the caller identity). The athena, glue and s3 helpers use data_account, which falls back to base.
  • _deploy() preflight in cross-account mode: requires --quicksight-datasource-id, validates the DataSource (Athena, CREATION_SUCCESSFUL / UPDATE_SUCCESSFUL, workgroup set, ConsumerAccountRoleArn in the data account and partition) and binds its workgroup before any Athena call.
  • Refused in cross-account mode: create_datasource(), crawler creation (checked before any table change; existing crawlers are left alone) and create_cur_table().
  • teardown keeps a CID-CMD-Athena DataSource that uses ConsumerAccountRoleArn, and the role it references.
  • Read-access policies are not attached in cross-account mode; a warning lists the data providers instead.
  • {account_id} in view parameter defaults and the Glue catalog id now use the data account (no change in single-account mode).
  • Connection parameters (CONNECTION_PARAMETERS, incl. athena-profile) are neither stored in nor loaded from cid_parameters.

cid/cli.py: help text for --athena-profile on deploy, update, delete, map, export, create-cur-proxy and teardown; --quicksight-datasource-id described as an ID, not an ARN.

docs/cid-cmd.md, CID-CMD.md: new "Cross-account (hub-and-spoke)" section with the three roles (DataSource role, consumer role, deployment role) incl. trust and permission policies, a create-data-source example, a command matrix, the checks and the limitations.

cid/test/python/test_cross_account.py: 37 new unit tests.

Out of scope

Listed as follow-ups in #1599:

  • creating the cross-account DataSource, crawlers and their roles from cid-cmd
  • CloudFormation / Lambda (rejected with a clear error)
  • a general preflight for delete, teardown and export

Pre-existing behaviour that this PR does not change: unknown --options are accepted silently, and CidCritical exits with status 0.

Testing

  • pytest cid/test/python/: 363 passed (37 new)
  • Lab, two accounts in eu-central-1:
    • deploy and update --recursive of cudos-v5 succeed; all views are created in the data account, none in the Quick account
    • SPICE refreshes run in the data account's workgroup
    • mismatching --athena-workgroup stops before touching Athena
    • forgotten --athena-profile stops before touching Athena
  • Single-account behaviour covered by the existing test suite and by test_without_profile_everything_uses_base_account

Security

The change opens a second AWS session. Credentials are handled entirely by boto3 through the named profile; cid-cmd neither reads, logs nor stores them. Happy to go through an AppSec review if needed.

Allow QuickSight in one account (hub) and Athena, Glue and S3 in
another (spoke) via --athena-profile, a named AWS profile for a role
in the data account. QuickSight, IAM, CFN and Organizations keep the
base session.

deploy/update require a DataSource with ConsumerAccountRoleArn in the
data account and bind its workgroup before any Athena call. Creating
datasources, crawlers and CUR tables is refused in this mode, as is
Lambda/CloudFormation. Connection parameters are not stored in
cid_parameters.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cid-cmd: support Quick cross-account Athena data sources (hub-and-spoke)

1 participant