Security

Security is an important topic between clients and the Avatica server. Most JDBCdrivers and databases implement some level of authentication and authorizationfor limit what actions clients are allowed to perform.

Similarly, Avatica must limit what users are allowed to connect and interactwith the server. Avatica must primarily deal with authentication while authorizationis deferred to the underlying database. By default, Avatica provides no authentication.Avatica does have the ability to perform client authentication using Kerberos,HTTP Basic, and HTTP Digest.

The authentication and authorization provided by Avatica are designed for useinstead of the authentication and authorization provided by the underlying database.The typical user and password JDBC properties are always passed through tothe Avatica server which will cause the server to enforce those credentials. As such,Avatica’s authentication types mentioned here only have relevance when the underlying database’s authenticationand authorization features are not used. (The Kerberos/SPNEGO integration is one difference as the impersonation featureis specifically designed to allow the Kerberos identity to be passed to the database -new advanced implementations could also follow this same approach if desired).

Table of Contents

HTTP Basic Authentication

Avatica supports authentication over HTTP Basic.This is simple username-password based authentication which is ultimately insecure whenoperating over an untrusted network. Basic authentication is only secure when the transportis encrypted (e.g. TLS) as the credentials are passed in the clear. This authentication issupplementary to the provided JDBC authentication. If credentials are passed to the databasealready, this authentication is unnecessary.

Enabling Basic Authentication

  1. String propertiesFile = "/path/to/jetty-users.properties";
  2. // All roles allowed
  3. String[] allowedRoles = new String[] {"*"};
  4. // Only specific roles are allowed
  5. allowedRoles = new String[] { "users", "admins" };
  6. HttpServer server = new HttpServer.Builder()
  7. .withPort(8765)
  8. .withHandler(new LocalService(), Driver.Serialization.PROTOBUF)
  9. .withBasicAuthentication(propertiesFile, allowedRoles)
  10. .build();

The properties file must be in a form consumable by Jetty. Each line in thisfile is of the form: username: password[,rolename …]

For example:

  1. bob: b0b5pA55w0rd,users
  2. steve: 5teve5pA55w0rd,users
  3. alice: Al1cepA55w0rd,admins

Passwords can also be obfuscated as MD5 hashes or oneway cryptography (“CRYPT”).For more information, see the official Jetty documentation.

HTTP Digest Authentication

Avatica also supports HTTP Digest.This is desirable for Avatica as it does not require the use of TLS to secure communicationbetween the Avatica client and server. It is configured very similarly to HTTP Basicauthentication. This authentication is supplementary to the provided JDBC authentication.If credentials are passed to the database already, this authentication is unnecessary.

Enabling Digest Authentication

  1. String propertiesFile = "/path/to/jetty-users.properties";
  2. // All roles allowed
  3. String[] allowedRoles = new String[] {"*"};
  4. // Only specific roles are allowed
  5. allowedRoles = new String[] { "users", "admins" };
  6. HttpServer server = new HttpServer.Builder()
  7. .withPort(8765)
  8. .withHandler(new LocalService(), Driver.Serialization.PROTOBUF)
  9. .withDigestAuthentication(propertiesFile, allowedRoles)
  10. .build();

The properties file must be in a form consumable by Jetty. Each line in thisfile is of the form: username: password[,rolename …]

For example:

  1. bob: b0b5pA55w0rd,users
  2. steve: 5teve5pA55w0rd,users
  3. alice: Al1cepA55w0rd,admins

Passwords can also be obfuscated as MD5 hashes or oneway cryptography (“CRYPT”).For more information, see the official Jetty documentation.

Kerberos with SPNEGO Authentication

Because Avatica operates over an HTTP interface, the simple and protected GSSAPInegotiation mechanism (SPNEGO) is a logicalchoice. This mechanism makes use of the “HTTP Negotiate” authentication extension tocommunicate with the Kerberos Key Distribution Center (KDC) to authenticate a client.

Enabling SPNEGO/Kerberos Authentication in servers

The Avatica server can operate either by performing the login usinga JAAS configuration file or login programmatically. By default, authenticated clientswill have queries executed as the Avatica server’s kerberos user. Impersonationis the feature which enables actions to be run in the server as the actual end-user.

As a note, it is required that the Kerberos principal in use by the Avatica servermust have an primary of HTTP (where Kerberos principals are of the formprimary[/instance]@REALM). This is specified by RFC-4559.

Programmatic Login

This approach requires no external file configurations and only requires akeytab file for the principal.

  1. HttpServer server = new HttpServer.Builder()
  2. .withPort(8765)
  3. .withHandler(new LocalService(), Driver.Serialization.PROTOBUF)
  4. .withSpnego("HTTP/host.domain.com@DOMAIN.COM")
  5. .withAutomaticLogin(
  6. new File("/etc/security/keytabs/avatica.spnego.keytab"))
  7. .build();

JAAS Configuration File Login

A JAAS configuration file can be set via the system property java.security.auth.login.config.The user must set this property when launching their Java application invoking the Avatica server.The presence of this file will automatically perform login as necessary in the first useof the Avatica server. The invocation is nearly the same as the programmatic login.

  1. HttpServer server = new HttpServer.Builder()
  2. .withPort(8765)
  3. .withHandler(new LocalService(), Driver.Serialization.PROTOBUF)
  4. .withSpnego("HTTP/host.domain.com@DOMAIN.COM")
  5. .build();

The contents of the JAAS configuration file are very specific:

  1. com.sun.security.jgss.accept {
  2. com.sun.security.auth.module.Krb5LoginModule required
  3. storeKey=true
  4. useKeyTab=true
  5. keyTab=/etc/security/keytabs/avatica.spnego.keyTab
  6. principal=HTTP/host.domain.com@DOMAIN.COM;
  7. };

Ensure the keyTab and principal attributes are set correctly for your system.

Impersonation

Impersonation is a feature of the Avatica server which allows the Avatica clientsto execute the server-side calls (e.g. the underlying JDBC calls). Because the detailson what it means to execute such an operation are dependent on the actual system, acallback is exposed for downstream integrators to implement.

For example, the following is an example for creating an Apache Hadoop UserGroupInformation“proxy user”. This example takes a UserGroupInformation object representing the Avatica server’sidentity, creates a “proxy user” with the client’s username, and performs the action as thatclient but using the server’s identity.

  1. public class PhoenixDoAsCallback implements DoAsRemoteUserCallback {
  2. private final UserGroupInformation serverUgi;
  3. public PhoenixDoAsCallback(UserGroupInformation serverUgi) {
  4. this.serverUgi = Objects.requireNonNull(serverUgi);
  5. }
  6. @Override
  7. public <T> T doAsRemoteUser(String remoteUserName, String remoteAddress, final Callable<T> action) throws Exception {
  8. // Proxy this user on top of the server's user (the real user)
  9. UserGroupInformation proxyUser = UserGroupInformation.createProxyUser(remoteUserName, serverUgi);
  10. // Check if this user is allowed to be impersonated.
  11. // Will throw AuthorizationException if the impersonation as this user is not allowed
  12. ProxyUsers.authorize(proxyUser, remoteAddress);
  13. // Execute the actual call as this proxy user
  14. return proxyUser.doAs(new PrivilegedExceptionAction<T>() {
  15. @Override
  16. public T run() throws Exception {
  17. return action.call();
  18. }
  19. });
  20. }
  21. }

Remote user extraction

In some cases, it may be desirable to execute some queries on behalf of another user. For example,Apache Knox has a gateway service which can act as a proxy for all requeststo the backend Avatica server. In this case, we don’t want to run the queries as the Knox user, insteadthe real user communicating with Knox.

There are presently two options to extract the “real” user from HTTP requests:

  • The authenticated user from the HTTP request, org.apache.calcite.avatica.server.HttpRequestRemoteUserExtractor (default)
  • The value of a parameter in the HTTP query string, org.apache.calcite.avatica.server.HttpQueryStringParameterRemoteUserExtractor (e.g “doAs”)

Implementations of Avatica can configure this using the AvaticaServerConfiguration and providingan implementation of RemoteUserExtractor. There are two implementations provided as listed above.

  1. config = new AvaticaServerConfiguration() {
  2. /* ... */
  3. @Override public RemoteUserExtractor getRemoteUserExtractor() {
  4. // We extract the "real" user via the "doAs" query string parameter
  5. return new HttpQueryStringParameterRemoteUserExtractor("doAs");
  6. }
  7. /* ... */
  8. };

Custom Authentication

Avatica server allows users to plugin their Custom Authenticationmechanism through the HTTPServer Builder. This is useful if userswant to combine features of various authentication types. Examplesinclude combining basic authentication with impersonation or addingmutual authentication with impersonation. More Examples are availablein CustomAuthHttpServerTest class.

Note: Users need to configure their own ServerConnectors andHandlers with the help of ServerCustomizers.

  1. AvaticaServerConfiguration configuration = new ExampleAvaticaServerConfiguration();
  2. HttpServer server = new HttpServer.Builder()
  3. .withCustomAuthentication(configuration)
  4. .withPort(8765)
  5. .build();

Client implementation

Many HTTP client libraries, such as Apache Commons HttpComponents, already havesupport for performing Basic, Digest, and SPNEGO authentication. When in doubt, refer to one ofthese implementations as it is likely correct.

SPNEGO

For information on building SPNEGO support by hand, consult RFC-4559which describes how the authentication handshake, through use of the “WWW-authenticate=Negotiate”HTTP header, is used to authenticate a client.

Password-based

For both HTTP Basic and Digest authentication, the avatica_userand avatica_passwordproperties are used to identify the client with the server. If the underlying database(the JDBC driver inside the Avatica server) require their own user and password combination,these are set via the traditional “user” and “password” properties in the AvaticaJDBC driver. This also implies that adding HTTP-level authentication in Avatica is likelysuperfluous.