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

feat: access control and user management with Keycloak #136

Merged
merged 42 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2886dae
feat: add security context in argo workflow spec
MyleneSimon Nov 20, 2019
d48ff12
feat: change default user to 1000/1000
MyleneSimon Nov 20, 2019
e633572
Merge branch 'master' into feature/add-pod-security-context-argo
MyleneSimon Feb 27, 2020
7754b64
Feature/keycloak (#128)
Mar 18, 2020
15c6788
Merge branch 'develop' into user-management
MyleneSimon Mar 18, 2020
17beaf3
feat: auth/access control (refactoring and fixes)
MyleneSimon May 18, 2020
b43e4d7
test: add test for data, workflow and job repositories
MyleneSimon May 19, 2020
f786846
fix: handle returnObject not found in @PostAuthorize in PrincipalFilt…
MyleneSimon May 20, 2020
5d131e9
test: add JobRepository tests
MyleneSimon May 20, 2020
2c3fc33
fix: open WorkflowExitController endpoint
MyleneSimon May 22, 2020
d9dba96
Merge branch 'develop' into feature/add-pod-security-context-argo
MyleneSimon May 28, 2020
f9acc72
Merge branch 'develop' into feature/add-pod-security-context-argo
MyleneSimon Jul 27, 2020
cf513e5
Merge branch 'develop' into user-management
MyleneSimon Aug 28, 2020
66eba01
feat: secure job deletion endpoint
MyleneSimon Aug 28, 2020
8cca9a8
feat: add download temp link management
MyleneSimon Sep 4, 2020
ad83332
feat: bump keycloak version, refactor, fix mongodb auto index creation
MyleneSimon Sep 8, 2020
9f2d114
fix: workflow copy controller
MyleneSimon Sep 8, 2020
d66bf45
feat: secure generic data endpoints + tests
MyleneSimon Sep 9, 2020
51f562d
feat: secure delete and save endpoints for generic data
MyleneSimon Sep 9, 2020
9639e62
feat: data must be locked before being shared
MyleneSimon Sep 16, 2020
b665543
feat: support for auth in wdzt
MyleneSimon Sep 18, 2020
1c4e0a1
fix: download controllers secured by token need security context to p…
MyleneSimon Sep 18, 2020
305ca00
feat: can make workflow and outputs public, add security to pyramid a…
MyleneSimon Sep 23, 2020
cafe867
feat: add keycloak conf management in docker
MyleneSimon Sep 24, 2020
0c2c640
chore: switch to wipp-keycloak database
MyleneSimon Sep 24, 2020
e1776bc
fix: keycloak config test in entrypoint
MyleneSimon Sep 24, 2020
072f128
fix: keycloak config test in entrypoint
MyleneSimon Sep 24, 2020
56319b8
fix: keycloak config test in entrypoint
MyleneSimon Sep 24, 2020
a3045cb
feat: keycloak log level
MyleneSimon Sep 24, 2020
2acfd22
fix: sed keycloak config
MyleneSimon Sep 25, 2020
61ff2a1
fix: session strategy and bearer-only setting
MyleneSimon Sep 25, 2020
26565e1
feat: stateless session management
MyleneSimon Sep 25, 2020
84eeaf7
feat: keycloak proxy url
MyleneSimon Sep 30, 2020
703ff78
fix: keycloak proxy url
MyleneSimon Sep 30, 2020
aeb9ec8
fix: keycloak trust manager
MyleneSimon Sep 30, 2020
f4249fc
fix: keycloak url
MyleneSimon Sep 30, 2020
4c1cea1
feat: keycloak disable trust manager as property
MyleneSimon Sep 30, 2020
7045f1a
chore: bump version to rc1
MyleneSimon Oct 2, 2020
4e302ea
Merge branch 'develop' into feature/add-pod-security-context-argo
MyleneSimon Oct 2, 2020
7c86aac
Merge pull request #157 from usnistgov/feature/add-pod-security-conte…
MyleneSimon Oct 2, 2020
4718537
chore: bump argo version
MyleneSimon Oct 2, 2020
1577cf3
docs: update dev instructions + rbac/acl doc
MyleneSimon Oct 5, 2020
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
19 changes: 17 additions & 2 deletions wipp-backend-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</activation>
<properties>
<mongodb.host>localhost</mongodb.host>
<mongodb.database>wipp-plugins</mongodb.database>
<mongodb.database>wipp-plugins-keycloak</mongodb.database>
<workflow.management.system>argo</workflow.management.system>
<workflow.binary>argo</workflow.binary>
<kube.wippdata.pvc>wippdata-pvc</kube.wippdata.pvc>
Expand Down Expand Up @@ -110,7 +110,6 @@
<ome.converter.threads>6</ome.converter.threads>
</properties>
</profile>

</profiles>

<dependencies>
Expand All @@ -124,6 +123,22 @@
<artifactId>wipp-backend-argo-workflows</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package gov.nist.itl.ssd.wipp.backend.app;

import org.keycloak.adapters.KeycloakDeployment;
import org.keycloak.adapters.KeycloakDeploymentBuilder;
import org.keycloak.adapters.spi.HttpFacade;
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
import org.keycloak.adapters.springboot.KeycloakSpringBootProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

/**
* This class is needed for Keycloak to work because of a bug in Keycloak : see https://stackoverflow.com/questions/57787768/issues-running-example-keycloak-spring-boot-app
*/

@Configuration
public class MyKeycloakSpringBootConfigResolver extends KeycloakSpringBootConfigResolver {

@Autowired
private KeycloakSpringBootProperties properties;

private KeycloakDeployment keycloakDeployment;

@Override
public KeycloakDeployment resolve(HttpFacade.Request facade) {
if (keycloakDeployment != null) {
return keycloakDeployment;
}

keycloakDeployment = KeycloakDeploymentBuilder.build(properties);
return keycloakDeployment;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package gov.nist.itl.ssd.wipp.backend.app;

import org.keycloak.adapters.springsecurity.KeycloakConfiguration;
import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider;
import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper;
import org.springframework.security.core.session.SessionRegistryImpl;
import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension;
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;

import gov.nist.itl.ssd.wipp.backend.core.CoreConfig;

/**
* Keycloak/Spring security configuration
*/
@KeycloakConfiguration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true,
securedEnabled = true,
jsr250Enabled = true)
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter
{


@Bean
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
return new SecurityEvaluationContextExtension();
}

/**
* Registers the KeycloakAuthenticationProvider with the authentication manager.
* SimpleAuthorityMapper is used to make sure roles are not prefixed with ROLE_
*/
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
KeycloakAuthenticationProvider keycloakAuthenticationProvider
= keycloakAuthenticationProvider();
keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(
new SimpleAuthorityMapper());
auth.authenticationProvider(keycloakAuthenticationProvider);
}

/**
* Defines the session authentication strategy.
*/
@Bean
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}

/**
* Configures HTTP security
*/
@Override
protected void configure(HttpSecurity http) throws Exception
{
super.configure(http);

http
.csrf().disable()
// restrict Create/Update/Delete operations to authenticated users
.authorizeRequests()
.antMatchers(HttpMethod.POST).authenticated()
.antMatchers(HttpMethod.PUT).authenticated()
.antMatchers(HttpMethod.PATCH).authenticated()
.antMatchers(HttpMethod.DELETE).authenticated()
.anyRequest().permitAll()
// return 401 Unauthorized instead of 302 redirect to login page
// for unauthorized access by anonymous user
.and()
.exceptionHandling()
.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED));
}

/**
* Exclude workflow exit controller from requiring authentication to allow Argo
* to POST workflow exit status
*/
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(HttpMethod.POST, CoreConfig.BASE_URI + "/workflows/{workflowId}/exit");
}
}
18 changes: 18 additions & 0 deletions wipp-backend-application/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,21 @@ logging.path=logs
logging.level.org.springframework.web=INFO
logging.level.loci.formats.in=WARN
server.tomcat.accessLogEnabled=true

# Keycloak configuration
# Name of the Keycloak realm
keycloak.realm=WIPPKeycloak
# URL of Keycloak's auth server
keycloak.auth-server-url=http://localhost:8081/auth
keycloak.cors=true
# SSL not required in dev
keycloak.ssl-required=none
# Name of Keycloak client
keycloak.resource=wipp-keycloak-client
keycloak.public-client=true
# Needed because of https://stackoverflow.com/questions/53318134/unable-to-use-keycloak-in-spring-boot-2-1-due-to-duplicated-bean-registration-ht
spring.main.allow-bean-definition-overriding=true
# Uncomment to enable Keycloak's debug logging
logging.level.org.keycloak=DEBUG
# This will map principal.name to the connected user's username
keycloak.principal-attribute=preferred_username
Loading