Skip to content

OWLS-84517: Scaling failed when setting Dedicated to true #1921

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

Merged
merged 2 commits into from
Sep 17, 2020
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
4 changes: 4 additions & 0 deletions operator/src/main/java/oracle/kubernetes/operator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ public static DomainNamespaceSelectionStrategy getDomainNamespaceSelectionStrate
return strategy;
}

public static String getOperatorNamespace() {
return operatorNamespace;
}

public static boolean isDedicated() {
return DomainNamespaceSelectionStrategy.Dedicated.equals(getDomainNamespaceSelectionStrategy());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class AuthenticationProxy {
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");

private static final AuthorizationProxy authorizationProxy = new AuthorizationProxy();
private static AuthorizationProxy authorizationProxy = new AuthorizationProxy();

/**
* Check if the specified access token can be authenticated.
Expand All @@ -25,7 +25,7 @@ public class AuthenticationProxy {
* @return V1TokenReviewStatus containing either info about the authenticated user or an error
* explaining why the user couldn't be authenticated
*/
public V1TokenReviewStatus check(String principal, String token) {
public V1TokenReviewStatus check(String principal, String token, String namespace) {

LOGGER.entering(principal); // Don't expose the token since it's a credential

Expand All @@ -37,8 +37,8 @@ public V1TokenReviewStatus check(String principal, String token) {
AuthorizationProxy.Operation.create,
AuthorizationProxy.Resource.TOKENREVIEWS,
null,
AuthorizationProxy.Scope.cluster,
null);
namespace == null ? AuthorizationProxy.Scope.cluster : AuthorizationProxy.Scope.namespace,
namespace);
if (allowed) {
result = new CallBuilder().createTokenReview(prepareTokenReview(token));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1TokenReviewStatus;
import io.kubernetes.client.openapi.models.V1UserInfo;
import oracle.kubernetes.operator.Main;
import oracle.kubernetes.operator.helpers.AuthenticationProxy;
import oracle.kubernetes.operator.helpers.AuthorizationProxy;
import oracle.kubernetes.operator.helpers.AuthorizationProxy.Operation;
Expand Down Expand Up @@ -133,7 +134,8 @@ private String getNamespace(String domainUid) {

private V1UserInfo authenticate(String accessToken) {
LOGGER.entering();
V1TokenReviewStatus status = atn.check(principal, accessToken);
V1TokenReviewStatus status = atn.check(principal, accessToken,
Main.isDedicated() ? Main.getOperatorNamespace() : null);
if (status == null) {
throw new AssertionError(LOGGER.formatMessage(MessageKeys.NULL_TOKEN_REVIEW_STATUS));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2020, Oracle Corporation and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.kubernetes.operator.helpers;

import java.util.ArrayList;
import java.util.List;

import com.meterware.simplestub.Memento;
import com.meterware.simplestub.StaticStubSupport;
import oracle.kubernetes.operator.helpers.AuthorizationProxy.Scope;
import oracle.kubernetes.utils.TestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.junit.MatcherAssert.assertThat;

public class AuthenticationProxyTest {

private final List<Memento> mementos = new ArrayList<>();
private final KubernetesTestSupport testSupport = new KubernetesTestSupport();
private final AuthorizationProxyStub authorizationProxyStub = new AuthorizationProxyStub();

/**
* Setup test.
* @throws Exception on failure
*/
@Before
public void setUp() throws Exception {
mementos.add(TestUtils.silenceOperatorLogger());
mementos.add(testSupport.install());
mementos.add(
StaticStubSupport.install(AuthenticationProxy.class, "authorizationProxy", authorizationProxyStub));
}

@After
public void tearDown() {
mementos.forEach(Memento::revert);
}

@Test
public void verify_authorizationScope_isCluster_whenNamespaceIsNull() {
AuthenticationProxy authorizationProxy = new AuthenticationProxy();
authorizationProxy.check("", "", null);
assertThat(authorizationProxyStub.scope, equalTo(Scope.cluster));
}

@Test
public void verify_authorizationScope_isNamespace_whenNamespaceIsDefined() {
AuthenticationProxy authorizationProxy = new AuthenticationProxy();
authorizationProxy.check("", "", "NS");
assertThat(authorizationProxyStub.scope, equalTo(Scope.namespace));
}

private class AuthorizationProxyStub extends AuthorizationProxy {
Scope scope;

public boolean check(
String principal,
Operation operation,
Resource resource,
String resourceName,
Scope scope,
String namespaceName) {
this.scope = scope;
return true;
}
}
}