Skip to content

GCP-3078: Bind Permissions To Lowest Level Resource#73

Merged
tedkahwaji merged 2 commits into
mainfrom
teddy.kahwaji/gcp-xxxx/bind-roles
Nov 4, 2025
Merged

GCP-3078: Bind Permissions To Lowest Level Resource#73
tedkahwaji merged 2 commits into
mainfrom
teddy.kahwaji/gcp-xxxx/bind-roles

Conversation

@tedkahwaji
Copy link
Copy Markdown
Collaborator

@tedkahwaji tedkahwaji commented Nov 2, 2025

Summary

This change updates the Dataflow script to reduce the scope of permissions granted to the Dataflow service account. Instead of assigning multiple roles at the project level, the script now grants only the permissions required for the specific resources used by the Dataflow job.

Changes

  • The service account will retain only the roles/dataflow.worker role at the project level.

  • It will now be granted:

    • Publisher role on the dead-letter topic.
    • Subscriber and Viewer roles on both created subscriptions.
  • A dedicated temporary storage bucket is now created for each Dataflow job in its respective region.

    • Previously, no bucket was specified and GCP auto-created a temporary bucket.
    • This required roles/storage.admin at the project level—an unnecessarily broad permission scope.
    • The updated implementation limits this role to the new bucket only.
  • The script now accepts additional configuration parameters for the Dataflow job, including:

    • isStreamingEngineEnabled
    • parallelism
    • batchCount
    • maxNumWorkers
    • numWorkers

    UI Preview:

Screenshot 2025-11-02 at 8 48 47 PM Screenshot 2025-11-02 at 8 49 02 PM Screenshot 2025-11-02 at 8 49 11 PM

Additional Notes

The new bucket’s name does not follow the same naming convention as other resources. This is intentional, as GCP bucket names must be globally unique. To ensure uniqueness, the project ID is appended to the bucket name.

@tedkahwaji tedkahwaji changed the title GCP-XXXX: GCP-XXXX: Bind Permissions To Lowest Level Resource Nov 3, 2025
@tedkahwaji tedkahwaji force-pushed the teddy.kahwaji/gcp-xxxx/bind-roles branch from 95daae1 to da227cd Compare November 3, 2025 13:00
@tedkahwaji tedkahwaji marked this pull request as ready for review November 3, 2025 13:00
@tedkahwaji tedkahwaji requested a review from a team as a code owner November 3, 2025 13:00
@tedkahwaji tedkahwaji requested review from smclaughlin1 and removed request for a team November 3, 2025 13:00
@tedkahwaji tedkahwaji requested a review from ash-ddog November 3, 2025 13:00
@tedkahwaji tedkahwaji marked this pull request as draft November 3, 2025 13:00
@tedkahwaji tedkahwaji changed the title GCP-XXXX: Bind Permissions To Lowest Level Resource GCP-3078: Bind Permissions To Lowest Level Resource Nov 3, 2025
@tedkahwaji tedkahwaji marked this pull request as ready for review November 3, 2025 13:04
@tedkahwaji tedkahwaji force-pushed the teddy.kahwaji/gcp-xxxx/bind-roles branch from da227cd to 82692c1 Compare November 4, 2025 16:32
.param("--project", project_id)
.param("--filter", f"name={FULL_BUCKET_NAME}")
)
if len(bucket_search) == 1:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: maybe >= 1 for extra safety?

Copy link
Copy Markdown
Collaborator Author

@tedkahwaji tedkahwaji Nov 4, 2025

Choose a reason for hiding this comment

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

Bucket names must be globally unique, so it’s not possible to have a search result in more than 1 results; If I were filtering with the ~ command, it would match using a regular expression, which can return multiple results. However, in this case, we’re being intentional and using name= rather than name~ so you can only have one bucket that matches that condition

https://cloud.google.com/sdk/gcloud/reference/beta/topic/filters

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah makes sense/imagine its super unlikely but was mainly for the "just-in-case" pov

.param("--project", project_id)
.param("--location", region)
.flag("--uniform-bucket-level-access")
.param("--soft-delete-duration", "0s")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OOC why disabling this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is intentional to lower customer costs, this is the warning you get when it's enabled for the temporary bucket

image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ack makes sense!

step_reporter.report(message="Enabling Dataflow Prime for the job...")
create_dataflow_job_cmd.param("--additional-experiments", "enable_prime")
elif dataflow_configuration.machine_type:
create_dataflow_job_cmd.param(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: there's no logging here for like "Setting worker machine type to {config.machine_type}" not sure if that's intentional or not

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

good point, going to add it for consistency

Copy link
Copy Markdown
Contributor

@katherinekim-51 katherinekim-51 left a comment

Choose a reason for hiding this comment

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

would have someone else also review this but lgtm!

Copy link
Copy Markdown

@thekevinhuang thekevinhuang left a comment

Choose a reason for hiding this comment

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

I think the change looks good. One nit, I'd probably link documentation stating min required roles in the PR description in case it is needed in the future. Maybe even screenshots in case google pulls the rug and changes the docs without telling us ;)

@tedkahwaji tedkahwaji merged commit 31d2dfe into main Nov 4, 2025
2 checks passed
@tedkahwaji tedkahwaji deleted the teddy.kahwaji/gcp-xxxx/bind-roles branch November 4, 2025 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants