From 7747b27040e04c64a4f21f2f0af7e7819caf5799 Mon Sep 17 00:00:00 2001 From: Martin Weise <martin.weise@tuwien.ac.at> Date: Tue, 14 Mar 2023 12:45:14 +0100 Subject: [PATCH] Added proxy to nginx --- fda-authentication-service/Dockerfile | 7 +++---- .../main/java/at/tuwien/config/GatewayConfig.java | 5 ++--- fda-ui/.env.example | 4 +++- fda-ui/Dockerfile | 2 ++ fda-ui/nuxt.config.js | 15 +++++++++------ fda-ui/package.json | 2 +- fda-ui/pages/login.vue | 7 +++++-- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/fda-authentication-service/Dockerfile b/fda-authentication-service/Dockerfile index f5cfe08e18..a68b28577f 100644 --- a/fda-authentication-service/Dockerfile +++ b/fda-authentication-service/Dockerfile @@ -10,6 +10,7 @@ ENV KC_FEATURES=account-api ENV KC_DB=mariadb WORKDIR /opt/keycloak + # for demonstration purposes only, please make sure to use proper certificates in production instead RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore RUN /opt/keycloak/bin/kc.sh build @@ -20,7 +21,7 @@ COPY --from=config /opt/keycloak/ /opt/keycloak/ USER root -COPY dbrepo-realm.json /dbrepo-realm.json +COPY ./dbrepo-realm.json /dbrepo-realm.json ENV METADATA_USERNAME=root ENV METADATA_PASSWORD=dbrepo @@ -35,8 +36,6 @@ ENV KEYCLOAK_IMPORT=/dbrepo-realm.json ENV KEYCLOAK_ADMIN=keycloak ENV KEYCLOAK_ADMIN_PASSWORD=keycloak -VOLUME /tmp - -EXPOSE 9097 +USER 1000 ENTRYPOINT ["/opt/keycloak/bin/kc.sh", "start"] diff --git a/fda-gateway-service/rest-service/src/main/java/at/tuwien/config/GatewayConfig.java b/fda-gateway-service/rest-service/src/main/java/at/tuwien/config/GatewayConfig.java index a5f75df457..937479e041 100644 --- a/fda-gateway-service/rest-service/src/main/java/at/tuwien/config/GatewayConfig.java +++ b/fda-gateway-service/rest-service/src/main/java/at/tuwien/config/GatewayConfig.java @@ -11,11 +11,10 @@ public class GatewayConfig { @Bean public RouteLocator routes(RouteLocatorBuilder builder) { return builder.routes() - .route("authentication-service", r -> r.path("/api/auth/**", - "/api/user/**") + .route("authentication-service", r -> r.path("/api/auth/**") .and() .method("POST", "GET", "PUT", "DELETE") - .and() + .filters(f -> f.rewritePath("/api/auth/(?<segment>.*)", "/${segment}")) .uri("lb://authentication-service")) .route("broker-service", r -> r.path("/api/broker/**") .and() diff --git a/fda-ui/.env.example b/fda-ui/.env.example index 6d67c5eca9..00f7fc8871 100644 --- a/fda-ui/.env.example +++ b/fda-ui/.env.example @@ -1,8 +1,10 @@ # ATTENTION: remove the last slash for the gateway url # - CORRECT: http://localhost:9095 # - WRONG: http://localhost:9095/ +NODE_ENV=dev API="http://localhost:9095" BROKER_USERNAME=fda BROKER_PASSWORD=fda -SANDBOX=false +SANDBOX=true SHARED_FILESYSTEM=/tmp +CLIENT_SECRET= diff --git a/fda-ui/Dockerfile b/fda-ui/Dockerfile index 0df37b3162..e5ecd64738 100644 --- a/fda-ui/Dockerfile +++ b/fda-ui/Dockerfile @@ -41,6 +41,7 @@ EXPOSE 3000 EXPOSE 9100 ENV API=http://gateway-service:9095 +ENV KEYCLOAK=https://authentication-service:8443 ENV BROKER_USERNAME=fda ENV BROKER_PASSWORD=fda ENV SANDBOX=false @@ -52,6 +53,7 @@ ENV ELASTIC_PASSWORD=elastic ENV VERSION="${TAG}" ENV TITLE="Database Repository" ENV ICON="/favicon.ico" +ENV CLIENT_SECRET="" WORKDIR /app diff --git a/fda-ui/nuxt.config.js b/fda-ui/nuxt.config.js index 66d11e53c6..d537faae8a 100644 --- a/fda-ui/nuxt.config.js +++ b/fda-ui/nuxt.config.js @@ -10,6 +10,7 @@ if (process.env.SANDBOX) { const configTitle = process.env.TITLE || 'Database Repository' const configIcon = process.env.ICON || '/favicon.ico' +const sandbox = process.env.SANDBOX || false export default { target: 'server', @@ -40,10 +41,10 @@ export default { ], plugins: [ - { src: '~/plugins/toast', ssr: false }, - { src: '~/plugins/vendors', ssr: false }, - { src: '~/plugins/axios' }, - { src: '~/plugins/vuex-persist.js', mode: 'client' } + { src: '@/plugins/toast', ssr: false }, + { src: '@/plugins/vendors', ssr: false }, + { src: '@/plugins/axios' }, + { src: '@/plugins/vuex-persist.js', mode: 'client' } ], // Auto import components (https://go.nuxtjs.dev/config-components) @@ -75,16 +76,18 @@ export default { publicRuntimeConfig: { brokerUsername: process.env.BROKER_USERNAME || 'fda', brokerPassword: process.env.BROKER_PASSWORD || 'fda', - sandbox: process.env.SANDBOX || false, + sandbox, sharedFilesystem: process.env.SHARED_FILESYSTEM || '/tmp', version: process.env.VERSION || 'latest', logo: process.env.LOGO || '/logo.png', mailVerify: process.env.MAIL_VERIFY || false, tokenMax: process.env.TOKEN_MAX || 5, - elasticPassword: process.env.ELASTIC_PASSWORD || 'elastic' + elasticPassword: process.env.ELASTIC_PASSWORD || 'elastic', + client_secret: process.env.CLIENT_SECRET }, proxy: { + '/auth': process.env.KEYCLOAK || 'https://localhost:8443', '/api': process.env.API || 'http://localhost:9095', '/pid': { target: process.env.API + '/api' || 'http://localhost:9095/api', diff --git a/fda-ui/package.json b/fda-ui/package.json index 1649177b07..7d4b5cb16b 100644 --- a/fda-ui/package.json +++ b/fda-ui/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "private": true, "scripts": { - "dev": "nuxt --port 3001", + "dev": "export NODE_TLS_REJECT_UNAUTHORIZED=0 && nuxt --env.NODE_TLS_REJECT_UNAUTHORIZED=0 --port 3001", "docker": "nuxt > /dev/null", "build": "nuxt build", "start": "nuxt start", diff --git a/fda-ui/pages/login.vue b/fda-ui/pages/login.vue index 44ee3235cf..9457e6eb65 100644 --- a/fda-ui/pages/login.vue +++ b/fda-ui/pages/login.vue @@ -63,8 +63,11 @@ export default { error: false, // XXX: `error` is never changed valid: false, loginAccount: { + client_id: 'dbrepo-client', username: null, - password: null + password: null, + grant_type: 'password', + client_secret: this.$config.client_secret } } }, @@ -103,7 +106,7 @@ export default { async login () { try { this.loading = true - const res = await this.$axios.post('/api/auth', this.loginAccount) + const res = await this.$axios.post('/auth/realms/dbrepo/protocol/openid-connect/token', this.loginAccount) console.debug('login user', res.data) const { token } = res.data this.$store.commit('SET_TOKEN', token) -- GitLab