gianm commented on code in PR #19236:
URL: https://github.com/apache/druid/pull/19236#discussion_r3049886360
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/http/OverlordResource.java:
##########
@@ -185,6 +205,27 @@ public Response taskPost(
throw new ForbiddenException(authResult.getErrorMessage());
}
+ // Inject auth context if provider is configured
+ if (taskAuthContextProvider != null) {
+ final AuthenticationResult authenticationResult =
AuthorizationUtils.authenticationResultFromRequest(req);
Review Comment:
How will this work in the SQL DML path, where the user submits a task to
`/druid/v2/sql/task/` and the Broker then submits the task using its own
credentials? The current design is that the Broker authenticates the user,
authorizes the DML operation, and then submits it to the Overlord using a
service account (not the user's own credentials).
IMO it would make more sense in this case for the Broker to get the vended
credentials and pass them along to the Overlord.
##########
processing/src/main/java/org/apache/druid/auth/TaskAuthContext.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.auth;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import org.apache.druid.guice.annotations.ExtensionPoint;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+
+/**
+ * Holds authentication context that can be passed to tasks for accessing
external services
+ * that require user credentials (e.g., Iceberg REST Catalog with OAuth).
+ *
+ * <p>Implementations must ensure credentials are redacted during
serialization by applying
+ * {@link TaskAuthContextRedactionMixIn} to the ObjectMapper used for
persistence/logging.
+ * This follows the same pattern as {@link
org.apache.druid.metadata.PasswordProvider} and
+ * {@link org.apache.druid.metadata.PasswordProviderRedactionMixIn}.
+ *
+ * <p>The auth context is injected into tasks at submission time by {@code
TaskAuthContextProvider}
+ * and is available during task execution. It is NOT persisted to metadata
storage - only the
+ * non-sensitive fields (identity, metadata) are serialized.
+ *
+ * <p><b>Credential lifetime:</b> Vended credentials (OAuth tokens, STS
session tokens) have
+ * limited lifetimes, typically 1-12 hours. There is currently no credential
refresh mechanism,
+ * so long-running tasks may fail when credentials expire. Task restarts are
also not supported
+ * since the original credentials are not preserved.
+ *
+ * @see TaskAuthContextRedactionMixIn
+ */
+@ExtensionPoint
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
+public interface TaskAuthContext
Review Comment:
I didn't see an implementation of `TaskAuthContext` or
`TaskAuthContextProvider` in this PR. Are they meant to be added later? What
would they look like? I was wondering in particular what
`taskAuthContextProvider.createTaskAuthContext` would do exactly with the
`authenticationResult` that is passed in.
##########
processing/src/main/java/org/apache/druid/auth/TaskAuthContext.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.auth;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import org.apache.druid.guice.annotations.ExtensionPoint;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+
+/**
+ * Holds authentication context that can be passed to tasks for accessing
external services
+ * that require user credentials (e.g., Iceberg REST Catalog with OAuth).
+ *
+ * <p>Implementations must ensure credentials are redacted during
serialization by applying
+ * {@link TaskAuthContextRedactionMixIn} to the ObjectMapper used for
persistence/logging.
+ * This follows the same pattern as {@link
org.apache.druid.metadata.PasswordProvider} and
+ * {@link org.apache.druid.metadata.PasswordProviderRedactionMixIn}.
+ *
+ * <p>The auth context is injected into tasks at submission time by {@code
TaskAuthContextProvider}
+ * and is available during task execution. It is NOT persisted to metadata
storage - only the
+ * non-sensitive fields (identity, metadata) are serialized.
+ *
+ * <p><b>Credential lifetime:</b> Vended credentials (OAuth tokens, STS
session tokens) have
+ * limited lifetimes, typically 1-12 hours. There is currently no credential
refresh mechanism,
+ * so long-running tasks may fail when credentials expire. Task restarts are
also not supported
Review Comment:
Any thoughts on how to handle long-running tasks? I expect it will be a
problem. It's not uncommon for tasks to take hours.
##########
multi-stage-query/src/main/java/org/apache/druid/msq/sql/MSQTaskQueryMaker.java:
##########
@@ -171,7 +172,13 @@ public QueryResponse<Object[]> runQuery(final DruidQuery
druidQuery)
taskContext
);
- FutureUtils.getUnchecked(overlordClient.runTask(taskId, controllerTask),
true);
+ // Propagate auth context headers to Overlord for consumption
+ if (plannerContext.getAuthenticationResult() != null &&
plannerContext.getAuthenticationResult().getContext() != null) {
Review Comment:
What is the purpose of this? Authentication context is meant to be an
arbitrary extension-defined in-memory map. It may not in general take well to
being stuffed into a header. It may also include sensitive information that
shouldn't be sent in a header.
##########
processing/src/main/java/org/apache/druid/auth/TaskAuthContext.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.auth;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import org.apache.druid.guice.annotations.ExtensionPoint;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+
+/**
+ * Holds authentication context that can be passed to tasks for accessing
external services
+ * that require user credentials (e.g., Iceberg REST Catalog with OAuth).
+ *
+ * <p>Implementations must ensure credentials are redacted during
serialization by applying
+ * {@link TaskAuthContextRedactionMixIn} to the ObjectMapper used for
persistence/logging.
+ * This follows the same pattern as {@link
org.apache.druid.metadata.PasswordProvider} and
+ * {@link org.apache.druid.metadata.PasswordProviderRedactionMixIn}.
+ *
+ * <p>The auth context is injected into tasks at submission time by {@code
TaskAuthContextProvider}
+ * and is available during task execution. It is NOT persisted to metadata
storage - only the
+ * non-sensitive fields (identity, metadata) are serialized.
+ *
+ * <p><b>Credential lifetime:</b> Vended credentials (OAuth tokens, STS
session tokens) have
+ * limited lifetimes, typically 1-12 hours. There is currently no credential
refresh mechanism,
+ * so long-running tasks may fail when credentials expire. Task restarts are
also not supported
+ * since the original credentials are not preserved.
+ *
+ * @see TaskAuthContextRedactionMixIn
+ */
+@ExtensionPoint
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
+public interface TaskAuthContext
+{
+ /**
+ * Returns the authenticated identity (e.g., username, email, service
account name).
+ * This value is safe to serialize and log.
+ *
+ * @return the identity string
+ */
+ String getIdentity();
Review Comment:
The auth context is a `@JsonProperty` so I believe that means people can set
it explicitly when they submit tasks. Does anything bad happen if someone sets
a context and sets the identity to someone else? What do you think about
clearing the user-provided auth context, if any, in `OverlordResource`?
##########
processing/src/main/java/org/apache/druid/auth/TaskAuthContext.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.auth;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import org.apache.druid.guice.annotations.ExtensionPoint;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+
+/**
+ * Holds authentication context that can be passed to tasks for accessing
external services
+ * that require user credentials (e.g., Iceberg REST Catalog with OAuth).
+ *
+ * <p>Implementations must ensure credentials are redacted during
serialization by applying
+ * {@link TaskAuthContextRedactionMixIn} to the ObjectMapper used for
persistence/logging.
+ * This follows the same pattern as {@link
org.apache.druid.metadata.PasswordProvider} and
+ * {@link org.apache.druid.metadata.PasswordProviderRedactionMixIn}.
+ *
+ * <p>The auth context is injected into tasks at submission time by {@code
TaskAuthContextProvider}
+ * and is available during task execution. It is NOT persisted to metadata
storage - only the
+ * non-sensitive fields (identity, metadata) are serialized.
+ *
+ * <p><b>Credential lifetime:</b> Vended credentials (OAuth tokens, STS
session tokens) have
+ * limited lifetimes, typically 1-12 hours. There is currently no credential
refresh mechanism,
+ * so long-running tasks may fail when credentials expire. Task restarts are
also not supported
+ * since the original credentials are not preserved.
+ *
+ * @see TaskAuthContextRedactionMixIn
+ */
+@ExtensionPoint
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
+public interface TaskAuthContext
+{
+ /**
+ * Returns the authenticated identity (e.g., username, email, service
account name).
+ * This value is safe to serialize and log.
+ *
+ * @return the identity string
+ */
+ String getIdentity();
+
+ /**
+ * Returns sensitive credentials (e.g., OAuth tokens, API keys).
+ * This method MUST be redacted during serialization via {@link
TaskAuthContextRedactionMixIn}.
Review Comment:
This is over-eager, isn't it? The credentials must be serialized in some
cases. When we send a task spec from Overlord to the server that will actually
run the task, the credentials must be included. In some cases the nonredacted
task file will need to end up on disk, so it can be run. Perhaps this should
say "MUST be redacted when written to log files, the metadata store, or
returned from user-facing APIs".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]