-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Support Hive metastore impersonation #1441
Conversation
a937203
to
1299349
Compare
...c/main/java/io/prestosql/plugin/hive/authentication/KerberosHiveMetastoreAuthentication.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveConfig.java
Outdated
Show resolved
Hide resolved
Would it be sufficient to call |
1299349
to
72a6bdc
Compare
Thank you for the advise. I think it's sufficient too and replaced the delegation token logic with |
75aa6e9
to
d6623de
Compare
Hi, impersonation support is missed out for get table operation. is there any plan to add support for that as well? |
@AnupGS What is the use case for impersonation for read calls? We could certainly add those, but I'm not aware of any reason to do so. When using SQL standard authorization, Presto performs all the security checks using the security information provided by the metastore. |
@electrum this is required because HMS may impose additional checks on get_table call. @ebyhr @electrum I will share with you exact impersonation rules we have implemented. @ebyhr thanks for working on this! And apologies for not opening our impersonation impl earlier, as I promised. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
...-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastoreConfig.java
Outdated
Show resolved
Hide resolved
d6623de
to
c808dee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments. Well done!
presto-geospatial/src/test/java/io/prestosql/plugin/geospatial/TestSpatialJoins.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveContext.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveContext.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/HiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/cache/CachingHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftMetastore.java
Outdated
Show resolved
Hide resolved
set -xeuo pipefail | ||
|
||
presto-product-tests/bin/run_on_docker.sh \ | ||
singlenode-hive-impersonation \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.impersonationEnabled = thriftConfig.isImpersonationEnabled() && hiveMetastoreAuthentication instanceof KerberosHiveMetastoreAuthentication;
the impersonation is supported only when kerberos is enabled
i think with setUGI, we should support impersonation with and without kerberos
-- but this also signals we don't have a direct test for an impersonation, something that would fail when impersonation does not work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be visible if you add authorization
here. (It should be included here anyway, it contains TestRoles, this is important to run here)
When applying changes, please separate them from rebase (or delay rebase), so that the changes themselves can be viewed on GH ui. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, adding impersonation for get calls was more complicated than I thought. Thanks for doing that.
presto-hive/src/main/java/io/prestosql/plugin/hive/CreateEmptyPartitionProcedure.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveMetadata.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/HivePartitionManager.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/HivePartitionManager.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/HivePageSinkMetadataProvider.java
Outdated
Show resolved
Hide resolved
presto-iceberg/src/main/java/io/prestosql/plugin/iceberg/HiveTableOperations.java
Outdated
Show resolved
Hide resolved
presto-iceberg/src/main/java/io/prestosql/plugin/iceberg/IcebergMetadata.java
Outdated
Show resolved
Hide resolved
presto-iceberg/src/main/java/io/prestosql/plugin/iceberg/IcebergMetadata.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
set -xeuo pipefail | ||
|
||
presto-product-tests/bin/run_on_docker.sh \ | ||
singlenode-hive-impersonation \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be visible if you add authorization
here. (It should be included here anyway, it contains TestRoles, this is important to run here)
|
||
presto-product-tests/bin/run_on_docker.sh \ | ||
singlenode-kerberos-hive-impersonation \ | ||
-g storage_formats,cli,hdfs_impersonation,authorization,hive_file_header |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason to include cli
and hive_file_header
tests?
(@kokosing do you know why do we run cli
tests so often?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason to include those tests. I followed existing hdfs-impersonation tests.
c808dee
to
525e514
Compare
Let me push updated code once. Below comments are not yet applied. |
presto-hive/src/main/java/io/prestosql/plugin/hive/HivePartitionManager.java
Outdated
Show resolved
Hide resolved
...to-hive/src/main/java/io/prestosql/plugin/hive/metastore/SemiTransactionalHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftMetastoreUtil.java
Outdated
Show resolved
Hide resolved
Pushed so that we can share the current status. |
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveMetadataFactory.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveIdentity.java
Outdated
Show resolved
Hide resolved
@@ -86,6 +87,7 @@ | |||
implements HiveMetastore | |||
{ | |||
protected final HiveMetastore delegate; | |||
private final boolean impersonationEnabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this field if we add isImpersonationEnabled()
to HiveMetastore
. Then updateIdentity()
can simply call delegate.isImpersonationEnabled()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we always return false
in FileHiveMetastore and throw an exception in GlueHiveMetastore? At least, we can't inject ThriftHiveMetastoreConfig into FileHiveMetastore. We can do it in GlueHiveMetastore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, always false. we don't support impersonation there
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
I had a few comments, mostly around the usage of |
9736171
to
ed32e58
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments.
Thanks @ebyhr
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/metastore/thrift/ThriftHiveMetastore.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/authentication/HiveIdentity.java
Outdated
Show resolved
Hide resolved
|
||
private HiveIdentity() | ||
{ | ||
this(new ConnectorIdentity("dummy_identity", Optional.empty(), Optional.empty())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply:
this(new ConnectorIdentity("dummy_identity", Optional.empty(), Optional.empty())); | |
this.username = "dummy_identity"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still, I'd prefer the username
be Optional<String>
in this class.
There is only one place where getUsername()
is called, so it's not a big deal and improves clarify.
private HiveIdentity updateIdentity(HiveIdentity identity) | ||
{ | ||
// remove identity if not doing impersonation | ||
return delegate.isImpersonationEnabled() ? identity : HiveIdentity.none(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HiveIdentity.none()
is going to be used as a cache key many times at the same time, so using a singleton would be nice.
One more thing: we can remove |
ed32e58
to
2f64cbf
Compare
Actually I wonder how this is working, the set_ugi implementation in hive metastore server-side is like adding the user information in the session, and there is no additional impersonation or authentication implemented. In fact, the earlier version of implementation (delegation token based) looks pretty promising and follow what hive did internally. Have you guys tested this in the real secure hive metastore environment, for example, if you create a table, is it owned by the authenticated user (mostly presto) or the real impersonation user (end-user)? @ebyhr @findepi |
Fix #43