Skip to content

Commit 032c78a

Browse files
committed
fix(roles): ensure UserRolesSyncer always refreshes anonymous user
if we lose the redis data the user roles syncer would no longer reload the anonymous permissions. also this caps the number of retries that the refresh will do to something that aligns with the caching agents timeout value. The agent will get rescheduled after that point by the scheduler.
1 parent 42cc012 commit 032c78a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

fiat-roles/src/main/java/com/netflix/spinnaker/fiat/roles/UserRolesSyncer.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ public class UserRolesSyncer implements RunnableAgent {
7474

7575
@Value("${fiat.writeMode.retryIntervalMs:10000}")
7676
@Setter
77-
private long retryIntervalMs;
77+
private long retryIntervalMs = 10000;
78+
79+
@Value("${fiat.writeMode.syncDelayTimeoutMs:30000}")
80+
@Setter
81+
private long syncDelayTimeoutMs = 30000;
82+
83+
7884

7985
public void run() {
8086
syncAndReturn();
@@ -83,8 +89,12 @@ public void run() {
8389
public long syncAndReturn() {
8490
FixedBackOff backoff = new FixedBackOff();
8591
backoff.setInterval(retryIntervalMs);
92+
backoff.setMaxAttempts(Math.floorDiv(syncDelayTimeoutMs, retryIntervalMs) + 1);
8693
BackOffExecution backOffExec = backoff.start();
8794

95+
//after this point the execution will get rescheduled
96+
final long timeout = System.currentTimeMillis() + syncDelayTimeoutMs;
97+
8898
if (!isServerHealthy()) {
8999
log.warn("Server is currently UNHEALTHY. User permission role synchronization and " +
90100
"resolution may not complete until this server becomes healthy again.");
@@ -93,6 +103,8 @@ public long syncAndReturn() {
93103
while (true) {
94104
try {
95105
Map<String, UserPermission> combo = new HashMap<>();
106+
//force a refresh of the unrestricted user in case the backing repository is empty:
107+
combo.put(UnrestrictedResourceConfig.UNRESTRICTED_USERNAME, new UserPermission());
96108
Map<String, UserPermission> temp;
97109
if (!(temp = getUserPermissions()).isEmpty()) {
98110
combo.putAll(temp);
@@ -105,7 +117,7 @@ public long syncAndReturn() {
105117
} catch (ProviderException|PermissionResolutionException ex) {
106118
Status status = healthIndicator.health().getStatus();
107119
long waitTime = backOffExec.nextBackOff();
108-
if (waitTime == BackOffExecution.STOP) {
120+
if (waitTime == BackOffExecution.STOP || System.currentTimeMillis() > timeout) {
109121
log.error("Unable to resolve service account permissions.", ex);
110122
return 0;
111123
}

0 commit comments

Comments
 (0)