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

Chore/not/cors #86

Merged
merged 3 commits into from
Dec 5, 2024
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
3 changes: 1 addition & 2 deletions .github/workflows/deploy-prod&demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ jobs:
with:
app_name: service-catalog
environment: prod
java_version: '17'
java_version: '21'
coverage_file_path: ./target/site/jacoco/jacoco.xml
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GCP_SA_DIGDIR_FDK_GCR_KEY: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }}

deploy-prod:
name: Deploy to prod environment
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ jobs:
with:
app_name: service-catalog
environment: staging
java_version: '17'
java_version: '21'
coverage_file_path: ./target/site/jacoco/jacoco.xml
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GCP_SA_DIGDIR_FDK_GCR_KEY: ${{ secrets.GCP_SA_DIGDIR_FDK_GCR_KEY }}

deploy:
name: Deploy to staging environment
Expand All @@ -39,6 +38,4 @@ jobs:
if: ${{ github.actor == 'dependabot[bot]' }}
uses: Informasjonsforvaltning/workflows/.github/workflows/build.yaml@main
with:
java_version: '17'
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
java_version: '21'
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM eclipse-temurin:17-jre-alpine
FROM eclipse-temurin:21-jre-alpine

ARG USER=default
ENV HOME /home/$USER

Check warning on line 4 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build when pull request is created / Build, test, publish staging

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

ENV TZ=Europe/Oslo
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
Expand All @@ -18,4 +18,4 @@

COPY --chown=app:app /target/app.jar app.jar

CMD java -jar -XX:+UseZGC $JAVA_OPTS app.jar

Check warning on line 21 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build when pull request is created / Build, test, publish staging

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
2 changes: 1 addition & 1 deletion deploy/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ resources:
- service-service-catalog.yaml
images:
- name: service-catalog
newName: eu.gcr.io/digdir-fdk-infra/service-catalog
newName: ghcr.io/informasjonsforvaltning/service-catalog
newTag: $(GIT_COMMIT_SHA)
2 changes: 2 additions & 0 deletions deploy/demo/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ spec:
secretKeyRef:
name: commonurl-demo
key: SERVICE_CATALOG_BASE_URI
- name: CORS_ORIGIN_PATTERNS
value: https://*.demo.fellesdatakatalog.digdir.no
2 changes: 2 additions & 0 deletions deploy/prod/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ spec:
secretKeyRef:
name: commonurl-prod
key: SERVICE_CATALOG_BASE_URI
- name: CORS_ORIGIN_PATTERNS
value: https://*.fellesdatakatalog.digdir.no
2 changes: 2 additions & 0 deletions deploy/staging/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ spec:
secretKeyRef:
name: commonurl-staging
key: SERVICE_CATALOG_BASE_URI
- name: CORS_ORIGIN_PATTERNS
value: https://*.staging.fellesdatakatalog.digdir.no,http://localhost:*
26 changes: 13 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<version>3.4.0</version>
<relativePath/>
</parent>

<properties>
<java.release>17</java.release>
<java.release>21</java.release>
<java.encoding>UTF-8</java.encoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>${java.release}</maven.compiler.source>
<maven.compiler.target>${java.release}</maven.compiler.target>
<maven.exec.skip>false</maven.exec.skip>

<kotlin.version>1.9.23</kotlin.version>
<testcontainers.version>1.19.7</testcontainers.version>
<kotlin.version>2.1.0</kotlin.version>
<testcontainers.version>1.20.4</testcontainers.version>
</properties>

<dependencies>
Expand All @@ -47,7 +47,7 @@
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.4</version>
<version>8.0</version>
</dependency>

<!-- Kotlin dependencies -->
Expand All @@ -74,19 +74,19 @@
<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>jakarta.json</artifactId>
<version>1.1.5</version>
<version>1.1.7</version>
</dependency>

<!-- RDF -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>5.0.0</version>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>5.0.0</version>
<version>5.2.0</version>
</dependency>

<!-- Test -->
Expand All @@ -104,7 +104,7 @@
<dependency>
<groupId>org.mockito.kotlin</groupId>
<artifactId>mockito-kotlin</artifactId>
<version>5.3.1</version>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -132,13 +132,13 @@
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>3.5.3</version>
<version>3.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.3.1</version>
<version>5.4.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -263,7 +263,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<version>3.5.2</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<argLine>${surefire.jacoco.args}</argLine>
Expand All @@ -277,7 +277,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.5</version>
<version>3.5.2</version>
<configuration>
<argLine>${failsafe.jacoco.args}</argLine>
<groups>integration</groups>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.digdir.servicecatalog.security

import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand All @@ -10,12 +11,28 @@ import org.springframework.security.oauth2.jwt.*
import org.springframework.security.oauth2.jwt.JwtClaimNames.AUD
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.config.annotation.web.invoke
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.CorsConfigurationSource

@Configuration
open class SecurityConfig {
open class SecurityConfig(
@Value("\${application.cors.originPatterns}")
val corsOriginPatterns: Array<String>
) {
@Bean
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
http {
cors {
configurationSource = CorsConfigurationSource {
val config = CorsConfiguration()
config.allowCredentials = false
config.allowedHeaders = listOf("*")
config.maxAge = 3600L
config.allowedOriginPatterns = corsOriginPatterns.toList()
config.allowedMethods = listOf("GET", "POST", "OPTIONS", "DELETE", "PATCH")
config
}
}
authorizeHttpRequests {
authorize(HttpMethod.GET, "/actuator/health/readiness", permitAll)
authorize(HttpMethod.GET, "/actuator/health/liveness", permitAll)
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spring:
jwk-set-uri: ${SSO_HOST}/auth/realms/fdk/protocol/openid-connect/certs
application:
serviceCatalogUri: ${SERVICE_CATALOG_URI}
cors.originPatterns: "${CORS_ORIGIN_PATTERNS}"
---
spring:
config.activate.on-profile: test
Expand All @@ -31,6 +32,7 @@ spring:
jwk-set-uri: http://localhost:5050/auth/realms/fdk/protocol/openid-connect/certs
application:
serviceCatalogUri: http://localhost:5050
cors.originPatterns: "*"
---
spring:
config.activate.on-profile: dev
Expand All @@ -43,3 +45,4 @@ spring:
jwk-set-uri: https://sso.staging.fellesdatakatalog.digdir.no/auth/realms/fdk/protocol/openid-connect/certs
application:
serviceCatalogUri: http://localhost:8080
cors.originPatterns: "*"