doc-locale/fr-fr/ci/secrets/fortanix_dsm_integration.md
{{< details >}}
{{< /details >}}
Vous pouvez utiliser Fortanix Data Security Manager (DSM) comme gestionnaire de secrets pour vos pipelines GitLab CI/CD.
Ce tutoriel explique les étapes nécessaires pour générer de nouveaux secrets dans Fortanix DSM, ou utiliser des secrets existants, et les utiliser dans les jobs GitLab CI/CD. Suivez attentivement les instructions pour mettre en œuvre cette intégration, renforcer la sécurité des données et optimiser vos pipelines CI/CD.
Assurez-vous de disposer des éléments suivants :
Pour générer un nouveau secret dans Fortanix DSM et l'utiliser avec GitLab :
Connectez-vous à votre compte Fortanix DSM.
Dans Fortanix DSM, créez un nouveau groupe et une application.
Configurez la clé API comme méthode d'authentification pour l'application.
Utilisez le code suivant pour générer un nouveau plugin dans Fortanix DSM :
numericAlphabet = "0123456789"
alphanumericAlphabet = numericAlphabet .. "abcdefghijklmnopqrstuvwxyz"
alphanumericCapsAlphabet = alphanumericAlphabet .. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alphanumericCapsSymbolsAlphabets = alphanumericCapsAlphabet .. "!@#$&*_%="
function genPass(alphabet, len, name, import)
local alphabetSize = #alphabet
local password = ''
for i = 1, len, 1 do
local random_char = math.random(alphabetSize)
password = password .. string.sub(alphabet, random_char, random_char)
end
local pass = Blob.from_bytes(password)
if import == "yes" then
local sobject = assert(Sobject.import { name = name, obj_type = "SECRET", value = pass, key_ops = {'APPMANAGEABLE', 'EXPORT'} })
return password
end
return password;
end
function run(input)
if input.type == "numeric" then
return genPass(numericAlphabet, input.length, input.name, input.import)
end
if input.type == "alphanumeric" then
return genPass(alphanumericAlphabet, input.length, input.name, input.import)
end
if input.type == "alphanumeric_caps" then
return genPass(alphanumericCapsAlphabet, input.length, input.name, input.import)
end
if input.type == "alphanumeric_caps_symbols" then
return genPass(alphanumericCapsSymbolsAlphabets, input.length, input.name, input.import)
end
end
Pour plus d'informations, consultez le Guide utilisateur Fortanix : Plugin Library.
Définissez l'option d'importation sur yes si vous souhaitez stocker le secret dans Fortanix DSM :
{
"type": "alphanumeric_caps",
"length": 64,
"name": "GitLab-Secret",
"import": "yes"
}
Définissez l'option d'importation sur no si vous souhaitez uniquement générer une nouvelle valeur pour la rotation :
{
"type": "numeric",
"length": 64,
"name": "GitLab-Secret",
"import": "no"
}
Dans la barre supérieure, sélectionnez Rechercher ou aller à et trouvez votre projet.
Dans la barre latérale gauche, sélectionnez Paramètres > CI/CD.
Développez Variables et ajoutez ces variables :
FORTANIX_API_ENDPOINTFORTANIX_API_KEYFORTANIX_PLUGIN_IDCréez ou modifiez le fichier de configuration .gitlab-ci.yml dans votre projet pour utiliser l'intégration :
stages:
- build
build:
stage: build
image: ubuntu
script:
- apt-get update
- apt install --assume-yes jq
- apt install --assume-yes curl
- jq --version
- curl --version
- secret=$(curl --silent --request POST --header "Authorization:Basic ${FORTANIX_API_KEY}" ${FORTANIX_API_ENDPOINT}/sys/v1/plugins/${FORTANIX_PLUGIN_ID} --data "{\"type\":\"alphanumeric_caps\", \"name\":\"$CI_PIPELINE_ID\",\"import\":\"yes\", \"length\":\"48\"}" | jq --raw-output)
- nsecret=$(curl --silent --request POST --header "Authorization:Basic ${FORTANIX_API_KEY}" ${FORTANIX_API_ENDPOINT}/sys/v1/plugins/${FORTANIX_PLUGIN_ID} --data "{\"type\":\"alphanumeric_caps\", \"import\":\"no\", \"length\":\"48\"}" | jq --raw-output)
- encodesecret=$(echo $nsecret | base64)
- rotate=$(curl --silent --request POST --header "Authorization:Basic ${FORTANIX_API_KEY}" ${FORTANIX_API_ENDPOINT}/crypto/v1/keys/rekey --data "{\"name\":\"$CI_PIPELINE_ID\", \"value\":\"$encodesecret\"}" | jq --raw-output .kid)
Le pipeline devrait s'exécuter automatiquement après l'enregistrement du fichier .gitlab-ci.yml. Sinon, sélectionnez Version > Pipelines > Exécuter le pipeline.
Accédez à Version > Jobs et vérifiez le job log du job build :
Pour utiliser un secret existant dans Fortanix DSM avec GitLab :
Le secret doit être marqué comme exportable dans Fortanix :
Dans la barre supérieure, sélectionnez Rechercher ou aller à et trouvez votre projet.
Dans la barre latérale gauche, sélectionnez Paramètres > CI/CD.
Développez Variables et ajoutez ces variables :
FORTANIX_API_ENDPOINTFORTANIX_API_KEYFORTANIX_PLUGIN_IDCréez ou modifiez le fichier de configuration .gitlab-ci.yml dans votre projet pour utiliser l'intégration :
stages:
- build
build:
stage: build
image: ubuntu
script:
- apt-get update
- apt install --assume-yes jq
- apt install --assume-yes curl
- jq --version
- curl --version
- secret=$(curl --silent --request POST --header "Authorization:Basic ${FORTANIX_API_KEY}" ${FORTANIX_API_ENDPOINT}/crypto/v1/keys/export --data "{\"name\":\"${FORTANIX_SECRET_NAME}\"}" | jq --raw-output .value)
Le pipeline devrait s'exécuter automatiquement après l'enregistrement du fichier .gitlab-ci.yml. Sinon, sélectionnez Version > Pipelines > Exécuter le pipeline.
Accédez à Version > Jobs et vérifiez le job log du job build :
Pour configurer la signature de code de manière sécurisée dans votre environnement GitLab :
Connectez-vous à votre compte Fortanix DSM.
Importez keystore_password et key_password comme secrets dans Fortanix DSM. Assurez-vous qu'ils sont marqués comme exportables.
Dans la barre supérieure, sélectionnez Rechercher ou aller à et trouvez votre projet.
Dans la barre latérale gauche, sélectionnez Paramètres > CI/CD.
Développez Variables et ajoutez ces variables :
FORTANIX_API_ENDPOINTFORTANIX_API_KEYFORTANIX_SECRET_NAME_1 (pour keystore_password)FORTANIX_SECRET_NAME_2 (pour key_password)Créez ou modifiez le fichier de configuration .gitlab-ci.yml dans votre projet pour utiliser l'intégration :
stages:
- build
build:
stage: build
image: ubuntu
script:
- apt-get update -qy
- apt install --assume-yes jq
- apt install --assume-yes curl
- apt-get install wget
- apt-get install unzip
- apt-get install --assume-yes openjdk-8-jre-headless openjdk-8-jdk # Install Java
- keystore_password=$(curl --silent --request POST --header "Authorization:Basic ${FORTANIX_API_KEY}" ${FORTANIX_API_ENDPOINT}/crypto/v1/keys/export --data "{\"name\":\"${FORTANIX_SECRET_NAME_1}\"}" | jq --raw-output .value)
- key_password=$(curl --silent --request POST --header "Authorization:Basic ${FORTANIX_API_KEY}" ${FORTANIX_API_ENDPOINT}/crypto/v1/keys/export --data "{\"name\":\"${FORTANIX_SECRET_NAME_2}\"}" | jq --raw-output .value)
- echo "yes" | keytool -genkeypair -alias mykey -keyalg RSA -keysize 2048 -keystore keystore.jks -storepass $keystore_password -keypass $key_password -dname "CN=test"
- mkdir -p src/main/java
- echo 'public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }' > src/main/java/HelloWorld.java
- javac src/main/java/HelloWorld.java
- mkdir -p target
- jar cfe target/HelloWorld.jar HelloWorld -C src/main/java HelloWorld.class
- jarsigner -keystore keystore.jks -storepass $keystore_password -keypass $key_password -signedjar signed.jar target/HelloWorld.jar mykey
Le pipeline devrait s'exécuter automatiquement après l'enregistrement du fichier .gitlab-ci.yml. Sinon, sélectionnez Version > Pipelines > Exécuter le pipeline.
Accédez à Version > Jobs et vérifiez le job log du job build :