-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #2529: SelfSubjectAccessReview broken with OpenShiftClient
Right now all create only resources in `authorization.k8s.io` apiGroup seem to be returning HTTP_OK/HTTP_CREATED even if there are no bearer token headers set in request. Due to this, we were always skipping token update since we only check for HTTP_UNAUTHORIZED/HTTP_FORBIDDEN response codes. Added an exception in OpenShiftOAuthInterceptor to always force token update in case url contains Kubernetes/OpenShift authorization apiGroup
- Loading branch information
1 parent
a2b67bf
commit bb0c32d
Showing
4 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
kubernetes-itests/src/test/java/io/fabric8/openshift/SelfSubjectAccessReviewIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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 io.fabric8.openshift; | ||
|
||
import io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReview; | ||
import io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReviewBuilder; | ||
import io.fabric8.openshift.client.OpenShiftClient; | ||
import org.arquillian.cube.kubernetes.api.Session; | ||
import org.arquillian.cube.openshift.impl.requirement.RequiresOpenshift; | ||
import org.arquillian.cube.requirement.ArquillianConditionalRunner; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(ArquillianConditionalRunner.class) | ||
@RequiresOpenshift | ||
public class SelfSubjectAccessReviewIT { | ||
@ArquillianResource | ||
OpenShiftClient client; | ||
|
||
@ArquillianResource | ||
Session session; | ||
|
||
@Test | ||
public void create() { | ||
// Given | ||
SelfSubjectAccessReview ssar = new SelfSubjectAccessReviewBuilder() | ||
.withNewSpec() | ||
.withNewResourceAttributes() | ||
.withGroup("apps") | ||
.withResource("deployments") | ||
.withVerb("create") | ||
.withNamespace(session.getNamespace()) | ||
.endResourceAttributes() | ||
.endSpec() | ||
.build(); | ||
|
||
// When | ||
ssar = client.authorization().v1().selfSubjectAccessReview().create(ssar); | ||
|
||
// Then | ||
assertTrue(ssar.getStatus().getAllowed()); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
kubernetes-itests/src/test/java/io/fabric8/openshift/SubjectAccessReviewIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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 io.fabric8.openshift; | ||
|
||
import io.fabric8.openshift.api.model.SubjectAccessReview; | ||
import io.fabric8.openshift.api.model.SubjectAccessReviewBuilder; | ||
import io.fabric8.openshift.api.model.SubjectAccessReviewResponse; | ||
import io.fabric8.openshift.client.OpenShiftClient; | ||
import org.arquillian.cube.kubernetes.api.Session; | ||
import org.arquillian.cube.openshift.impl.requirement.RequiresOpenshift; | ||
import org.arquillian.cube.requirement.ArquillianConditionalRunner; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
|
||
@RunWith(ArquillianConditionalRunner.class) | ||
@RequiresOpenshift | ||
public class SubjectAccessReviewIT { | ||
@ArquillianResource | ||
OpenShiftClient client; | ||
|
||
@ArquillianResource | ||
Session session; | ||
|
||
@Test | ||
public void testCreate() { | ||
// Given | ||
SubjectAccessReview sar = new SubjectAccessReviewBuilder() | ||
.withResource("Pod") | ||
.withVerb("get") | ||
.withNamespace(session.getNamespace()) | ||
.build(); | ||
|
||
// When | ||
SubjectAccessReviewResponse response = client.subjectAccessReviews().create(sar); | ||
|
||
// Then | ||
assertNotNull(response); | ||
assertTrue(response.getAllowed()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters