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

Add Identity API to QueryCtx and ConnectorQueryCtx #9982

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

majetideepak
Copy link
Collaborator

@majetideepak majetideepak commented May 30, 2024

Presto clients can provide extra credentials to a connector.
The Presto protocol sends this information as part of the TaskUpdateRequest.
Add an Identity API in Velox to support this.

Resolves: #10107

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 30, 2024
Copy link

netlify bot commented May 30, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 7ceb94b
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/6666a4be1b9c9a000872e7f0


namespace facebook::velox::common {

class Identity {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer plain struct if all the fields are real data. Class is only used to encapsulate temporary state, not real data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!

@Yuhta Yuhta requested a review from mbasmanova May 30, 2024 14:41
@majetideepak
Copy link
Collaborator Author

@mbasmanova please share your feedback on this API. The CI failures are due to a missing argument from this change. I will fix them. Thanks!

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@majetideepak Deepak, would you provide some more context about this change and how do you plan to develop it further. It might be nice to create a GitHub issue to explain overall thinking and describe development plan.

In Presto, Identity class has a lot more fields. Do you expect to add them all?

public class Identity
{
    private final String user;
    private final Optional<Principal> principal;
    private final Map<String, SelectedRole> roles;
    private final Map<String, String> extraCredentials;
    private final Optional<String> selectedUser;
    private final Optional<String> reasonForSelect;

    /**
     * extraAuthenticators is used when short-lived access token has to be refreshed periodically.
     * Otherwise, extraCredentials should be used to store pre-fetched long-lived access token.
     *
     * extraAuthenticators will not be serialized. It has to be injected on Presto worker directly.
     */
    private final Map<String, TokenAuthenticator> extraAuthenticators;

@majetideepak
Copy link
Collaborator Author

@mbasmanova I will open an issue with more design details. Thanks!

struct Identity {
Identity() = default;

Identity(
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for any constructors or getters

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

@majetideepak
Copy link
Collaborator Author

@mbasmanova I opened an issue here #10107 with some details on this.
Thanks!

@majetideepak majetideepak changed the title Add Identity API Add Identity API to QueryCtx and ConnectorQueryCtx Jun 7, 2024
@majetideepak majetideepak marked this pull request as ready for review June 7, 2024 12:36
@@ -331,6 +338,7 @@ class ConnectorQueryCtx {
memory::MemoryPool* const operatorPool_;
memory::MemoryPool* const connectorPool_;
const Config* const sessionProperties_;
const common::Identity* identity_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Storing raw pointers is not safe. Can we store this by value or use a smart pointer?

Copy link
Contributor

@Yuhta Yuhta Jun 7, 2024

Choose a reason for hiding this comment

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

I think it's not a big problem (rather a win in readability) since ConnectorQueryCtx is always outlived by QueryCtx. This way it's more readable that QueryCtx owns the object and ConnectorQueryCtx is just borrowing it.

namespace facebook::velox::common {

/// Used to store user name and credentials.
struct Identity {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to put this into 'security' namespace?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think so too! Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Identity API to QueryCtx and ConnectorQueryCtx
4 participants