adutra commented on code in PR #18754:
URL: https://github.com/apache/iceberg/pull/18754#discussion_r4468248877


##########
core/src/main/java/org/apache/iceberg/rest/auth/FileTokenSource.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.time.Duration;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.LongSupplier;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link BearerTokenSource} that reads the token from a local file, and 
re-reads it once the
+ * token is older than the configured reload interval.
+ *
+ * <p>No background thread is used: reloads happen lazily, on the calling 
thread, when the token is
+ * requested. Only one thread reloads at a time; concurrent callers get the 
current token without
+ * waiting.
+ *
+ * <p>If a reload fails, the last valid token is kept, and the next reload is 
attempted after a full
+ * reload interval. As a consequence, deleting the token file does not revoke 
the token.
+ */
+final class FileTokenSource implements BearerTokenSource {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(FileTokenSource.class);
+
+  /**
+   * Maximum token file size. Large enough for JWTs signed with the largest 
post-quantum signature
+   * schemes.
+   */
+  static final int MAX_FILE_SIZE = 256 * 1024;

Review Comment:
   We're protecting against a malicious token producer: without this guard, a 1 
gigabyte string could end up verbatim in the `Authorization` header, probably 
making either the client or the server crash.



-- 
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]

Reply via email to