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

[6.3.0] Use wall-time for credential helper invalidation #18413

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ filegroup(

java_library(
name = "credential_module",
srcs = ["CredentialModule.java"],
srcs = [
"CredentialModule.java",
"SystemMillisTicker.java",
],
deps = [
"//src/main/java/com/google/devtools/build/lib:runtime",
"//src/main/java/com/google/devtools/build/lib/authandtls",
Expand All @@ -23,7 +26,10 @@ java_library(
name = "credentialhelper",
srcs = glob(
["*.java"],
exclude = ["CredentialModule.java"],
exclude = [
"CredentialModule.java",
"SystemMillisTicker.java",
],
),
deps = [
"//src/main/java/com/google/devtools/build/lib/events",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
/** A module whose sole purpose is to hold the credential cache which is shared by other modules. */
public class CredentialModule extends BlazeModule {
private final Cache<URI, ImmutableMap<String, ImmutableList<String>>> credentialCache =
Caffeine.newBuilder().expireAfterWrite(Duration.ZERO).build();
Caffeine.newBuilder()
.expireAfterWrite(Duration.ZERO)
.ticker(SystemMillisTicker.INSTANCE)
.build();

/** Returns the credential cache. */
public Cache<URI, ImmutableMap<String, ImmutableList<String>>> getCredentialCache() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2023 The Bazel Authors. All rights reserved.
//
// Licensed 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 com.google.devtools.build.lib.authandtls.credentialhelper;

import com.github.benmanes.caffeine.cache.Ticker;

/**
* SystemMillisTicker is a Ticker which uses the unix epoch as its fixed reference point.
*
* <p>It is preferable to com.github.benmanes.caffeine.cache.Ticker.SystemTicker because that class
* doesn't increment its time-source while the system is asleep, which isn't appropriate when
* expiring tokens which have wall-time-based expiry policies.
*/
public class SystemMillisTicker implements Ticker {
public static final SystemMillisTicker INSTANCE = new SystemMillisTicker();

private SystemMillisTicker() {}

@Override
public long read() {
return System.currentTimeMillis() * 1_000_000;
}
}