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: System-managed and RBAC support to access to KV and Storage. #72

Merged
merged 5 commits into from
Oct 31, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 21 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.auth.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
*
* 23 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.client;
package it.pagopa.swclient.mil.auth.azure.auth.client;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import io.quarkus.rest.client.reactive.ClientQueryParam;
import io.smallrye.mutiny.Uni;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.GetAccessTokenResponse;
import it.pagopa.swclient.mil.auth.azure.auth.bean.GetAccessTokenResponse;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;

/**
Expand All @@ -22,17 +22,14 @@
@RegisterRestClient(configKey = "azure-auth-api")
public interface AzureAuthClient {
/**
* @param tenantId
* @param grantType
* @param clientId
* @param clientSecret
* @param identity
* @param scope
* @return
*/
@Path("?resource={scope}&api-version=2019-08-01")
@GET
@Produces(MediaType.APPLICATION_JSON)
@ClientQueryParam(name = "api-version", value = "${azure-auth-api.version}")
Uni<GetAccessTokenResponse> getAccessToken(
@HeaderParam("x-identity-header") String identity,
@PathParam("scope") String scope);
@QueryParam("resource") String scope);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* AzureAuthService.java
*
* 1 ago 2023
*/
package it.pagopa.swclient.mil.auth.azure.auth.service;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import it.pagopa.swclient.mil.auth.azure.auth.bean.GetAccessTokenResponse;
import it.pagopa.swclient.mil.auth.azure.auth.client.AzureAuthClient;
import jakarta.enterprise.context.ApplicationScoped;

/**
* @author Antonio Tarricone
*/
@ApplicationScoped
public class AzureAuthService {
/*
* Scopes for authentication.
*/
//private static final String VAULT = "https://vault.azure.net/.default";
public static final String VAULT = "https://vault.azure.net";
public static final String STORAGE = "https://storage.azure.com";

/*
*
*/
@RestClient
AzureAuthClient client;

/*
*
*/
@ConfigProperty(name = "azure-auth-api.identity")
String identity;

/**
* @return
*/
public Uni<GetAccessTokenResponse> getAccessToken() {
Log.debug("Authenticating to Azure AD for Key Vault.");
return client.getAccessToken(identity, VAULT);
}

/**
* @return
*/
public Uni<GetAccessTokenResponse> getAccessTokenForStorage() {
Log.debug("Authenticating to Azure AD for Storage Account.");
return client.getAccessToken(identity, STORAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 19 set 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 23 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 19 set 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 24 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 19 set 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 23 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 19 set 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 27 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 25 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 25 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 25 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 25 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.bean;
package it.pagopa.swclient.mil.auth.azure.keyvault.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
*
* 23 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.client;
package it.pagopa.swclient.mil.auth.azure.keyvault.client;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import io.quarkus.rest.client.reactive.ClientQueryParam;
import io.smallrye.mutiny.Uni;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.CreateKeyRequest;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.DetailedKey;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.GetKeysResponse;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.SignRequest;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.SignResponse;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.VerifySignatureRequest;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.VerifySignatureResponse;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.CreateKeyRequest;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.DetailedKey;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.GetKeysResponse;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.SignRequest;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.SignResponse;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.VerifySignatureRequest;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.VerifySignatureResponse;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 26 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.service;
package it.pagopa.swclient.mil.auth.azure.keyvault.service;

import java.time.Instant;
import java.util.Arrays;
Expand All @@ -20,15 +20,16 @@
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import it.pagopa.swclient.mil.auth.AuthErrorCode;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.BasicKey;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.CreateKeyRequest;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.DetailedKey;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.GetAccessTokenResponse;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.GetKeysResponse;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.KeyAttributes;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.KeyDetails;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.KeyNameAndVersion;
import it.pagopa.swclient.mil.auth.azurekeyvault.util.KidUtil;
import it.pagopa.swclient.mil.auth.azure.auth.bean.GetAccessTokenResponse;
import it.pagopa.swclient.mil.auth.azure.auth.service.AzureAuthService;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.BasicKey;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.CreateKeyRequest;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.DetailedKey;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.GetKeysResponse;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.KeyAttributes;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.KeyDetails;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.KeyNameAndVersion;
import it.pagopa.swclient.mil.auth.azure.keyvault.util.KidUtil;
import it.pagopa.swclient.mil.auth.bean.KeyType;
import it.pagopa.swclient.mil.auth.bean.KeyUse;
import it.pagopa.swclient.mil.auth.bean.PublicKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
*
* 27 lug 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.service;
package it.pagopa.swclient.mil.auth.azure.keyvault.service;

import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.CreateKeyRequest;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.DetailedKey;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.GetKeysResponse;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.SignRequest;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.SignResponse;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.VerifySignatureRequest;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.VerifySignatureResponse;
import it.pagopa.swclient.mil.auth.azurekeyvault.client.AzureKeyVaultClient;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.CreateKeyRequest;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.DetailedKey;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.GetKeysResponse;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.SignRequest;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.SignResponse;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.VerifySignatureRequest;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.VerifySignatureResponse;
import it.pagopa.swclient.mil.auth.azure.keyvault.client.AzureKeyVaultClient;
import jakarta.enterprise.context.ApplicationScoped;

/**
Expand All @@ -28,6 +28,7 @@ public class AzureKeyVaultService {
*
*/
private static final String BEARER = "Bearer ";

/*
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 1 ago 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.service;
package it.pagopa.swclient.mil.auth.azure.keyvault.service;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
Expand All @@ -21,9 +21,10 @@
import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import it.pagopa.swclient.mil.auth.AuthErrorCode;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.SignRequest;
import it.pagopa.swclient.mil.auth.azurekeyvault.bean.VerifySignatureRequest;
import it.pagopa.swclient.mil.auth.azurekeyvault.util.SignedJWTFactory;
import it.pagopa.swclient.mil.auth.azure.auth.service.AzureAuthService;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.SignRequest;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.VerifySignatureRequest;
import it.pagopa.swclient.mil.auth.azure.keyvault.util.SignedJWTFactory;
import it.pagopa.swclient.mil.auth.service.TokenSigner;
import it.pagopa.swclient.mil.auth.util.AuthError;
import it.pagopa.swclient.mil.auth.util.AuthException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*
* 1 ago 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.util;
package it.pagopa.swclient.mil.auth.azure.keyvault.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.microprofile.config.inject.ConfigProperty;

import it.pagopa.swclient.mil.auth.azurekeyvault.bean.KeyNameAndVersion;
import it.pagopa.swclient.mil.auth.azure.keyvault.bean.KeyNameAndVersion;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* 4 ago 2023
*/
package it.pagopa.swclient.mil.auth.azurekeyvault.util;
package it.pagopa.swclient.mil.auth.azure.keyvault.util;

import java.text.ParseException;

Expand Down
Loading
Loading