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(spanner): fine-grained access control #9669

Merged
merged 2 commits into from
Aug 11, 2022

Conversation

devbww
Copy link
Contributor

@devbww devbww commented Aug 10, 2022

Introduce spanner::SessionCreatorRoleOption, which can be passed to
spanner::MakeConnection() to set the session_template.creator_role
used when creating sessions for the connection.

Add integration test for creating and listing roles.

Add samples:

  • spanner_add_and_drop_database_roles
  • spanner_read_data_with_database_role
  • spanner_list_database_roles
  • spanner_enable_fine_grained_access

This change is Reviewable

Introduce `spanner::SessionCreatorRoleOption`, which can be passed to
`spanner::MakeConnection()` to set the `session_template.creator_role`
used when creating sessions for the connection.

Add integration test for creating and listing roles.

Add samples:
 - spanner_add_and_drop_database_roles
 - spanner_read_data_with_database_role
 - spanner_list_database_roles
 - spanner_enable_fine_grained_access
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Aug 10, 2022
@snippet-bot
Copy link

snippet-bot bot commented Aug 10, 2022

Here is the summary of changes.

You are about to add 4 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: e7dc8facc367f5fb6cbda2ab9ba19c1114d0016d

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@codecov
Copy link

codecov bot commented Aug 10, 2022

Codecov Report

Merging #9669 (8fe4e3d) into main (53795a0) will decrease coverage by 0.04%.
The diff coverage is 57.96%.

@@            Coverage Diff             @@
##             main    #9669      +/-   ##
==========================================
- Coverage   94.33%   94.29%   -0.05%     
==========================================
  Files        1494     1494              
  Lines      138952   139040      +88     
==========================================
+ Hits       131086   131104      +18     
- Misses       7866     7936      +70     
Impacted Files Coverage Δ
google/cloud/spanner/internal/session_pool.h 100.00% <ø> (ø)
google/cloud/spanner/samples/samples.cc 65.10% <1.56%> (-1.70%) ⬇️
google/cloud/spanner/internal/session_pool.cc 89.92% <76.92%> (-0.12%) ⬇️
...integration_tests/session_pool_integration_test.cc 100.00% <100.00%> (ø)
...gle/cloud/spanner/internal/connection_impl_test.cc 97.81% <100.00%> (+<0.01%) ⬆️
google/cloud/spanner/internal/session_pool_test.cc 99.70% <100.00%> (+0.01%) ⬆️
...loud/bigtable/internal/connection_refresh_state.cc 95.83% <0.00%> (-2.78%) ⬇️
...bigtable/examples/bigtable_hello_instance_admin.cc 81.00% <0.00%> (-2.00%) ⬇️
google/cloud/pubsub/subscriber_connection_test.cc 97.75% <0.00%> (-0.57%) ⬇️
...cloud/pubsub/internal/subscription_session_test.cc 97.98% <0.00%> (-0.17%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 8fe4e3d977fed28b7d7854c9ada3032e62114773

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@devbww devbww marked this pull request as ready for review August 10, 2022 03:55
@devbww devbww requested a review from a team as a code owner August 10, 2022 03:55
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

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

Some suggestions, but LGTM as-is.

@@ -84,6 +84,14 @@ using SpannerPolicyOptionList =
OptionList<spanner::SpannerRetryPolicyOption, SpannerBackoffPolicyOption,
SpannerPollingPolicyOption>;

/**
* Option for `google::cloud::Options` to set the database role used for
* session creation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider a link to the spanner documentation explaining what these what these roles are for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid I'm unaware of, and cannot discover, any released documentation. We can, of course, add something as it becomes available.

Copy link
Contributor

Choose a reason for hiding this comment

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

Later sounds good.

client.SetIamPolicy(database.FullName(), *std::move(policy));
if (!new_policy) throw std::runtime_error(new_policy.status().message());
std::cout << "Enabled fine-grained access in IAM. New policy has version "
<< new_policy->version() << "\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think that version is what you think it is. It is more like a code revision tracker than a state change tracker. You want something like the etag field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think I think it is anything in particular. It doesn't seem, at least, that the sample implies that it isn't a code-revision tracker.

That said, the shape of the output is defined by the internal "Fine Grained Access Control Samples" document, which is followed by all the other languages, so I'm not sure I'm in a position to change anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could try to talk the team into changing this example. As it is, it will print either 1 or 3 for the version.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please merge as-is though, we can implement (or not) both my suggestions at a later time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could try to talk the team into changing this example.

I can certainly do that. I'm not sure what I would write other than your comment verbatim however, so I'm also happy to point you at the doc. Let me know offline.

As it is, it will print either 1 or 3 for the version.

I thought it would always print (at least) 3, given that's what we raised the minimum version to above.

@devbww devbww merged commit bacbe2e into googleapis:main Aug 11, 2022
@devbww devbww deleted the fine-grained-access branch August 11, 2022 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants