Skip to content

Commit

Permalink
feat: change bin name from mna to infra (#97)
Browse files Browse the repository at this point in the history
* feat: change bin name from mna to infra

* feat: iso completion name

* fix: revert zsh completion
  • Loading branch information
antoinebigard authored Nov 22, 2024
1 parent 92f1b0e commit a2676e9
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .bin/commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Help() {
}

function bin:setup() {
sudo ln -fs "${ROOT_DIR}/.bin/mna" "/usr/local/bin/mna-infra"
sudo ln -fs "${ROOT_DIR}/.bin/infra" "/usr/local/bin/mna-infra"

sudo mkdir -p /usr/local/share/zsh/site-functions
sudo ln -fs "${ROOT_DIR}/.bin/zsh-completion" "/usr/local/share/zsh/site-functions/_mna-infra"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion .bin/scripts/ovh/close-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readonly ENV_NAME=${1:?"Merci de préciser un environnement (ex. recette ou prod
readonly MODULE_DIR="${SCRIPT_DIR}/ovh/ovh-nodejs-client"

function main() {
local env_ip=$("${BIN_DIR}/mna.sh" product:env:ip "${PRODUCT_NAME}" "${ENV_NAME}")
local env_ip=$("${BIN_DIR}/infra.sh" product:env:ip "${PRODUCT_NAME}" "${ENV_NAME}")
if [ -z $env_ip ]; then exit 1; fi

cd "${MODULE_DIR}"
Expand Down
2 changes: 1 addition & 1 deletion .bin/scripts/ovh/create-firewall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readonly PRODUCT_NAME=${1:?"Merci le produit (bal, tdb)"}; shift;
readonly ENV_NAME=${1:?"Merci de préciser un environnement (ex. recette ou production)"}; shift;

function main() {
local env_ip=$("${BIN_DIR}/mna" product:env:ip "${PRODUCT_NAME}" "${ENV_NAME}")
local env_ip=$("${BIN_DIR}/infra" product:env:ip "${PRODUCT_NAME}" "${ENV_NAME}")
if [ -z $env_ip ]; then exit 1; fi

cd "${SCRIPT_DIR}/ovh/ovh-nodejs-client"
Expand Down
2 changes: 1 addition & 1 deletion .bin/zsh-completion
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _mna-infra_completion() {
typeset -A opt_args
local -a commands=(
"help:Show help message"
"bin\:setup:Installs mna-bal binary with zsh completion on system"
"bin\:setup:Installs mna-infra binary with zsh completion on system"
"release\:proxy:Release docker reverse proxy image"
"release\:fluentd:Release fluentd reverse proxy image"
"system\:setup:Setup server"
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/_password-rotate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
steps:
- name: Checkout project
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
Expand All @@ -70,14 +70,14 @@ jobs:
VAULT_PWD: ${{ secrets.VAULT_PWD }}

- name: Run playbook
run: ".bin/mna password:rotate ${{ inputs.product }} ${{ inputs.environment }}"
run: ".bin/infra password:rotate ${{ inputs.product }} ${{ inputs.environment }}"
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
ANSIBLE_REMOTE_USER: deploy
ANSIBLE_BECOME_PASS: ${{ secrets.DEPLOY_PASS }}

- name: Encrypt logs
run: .bin/mna deploy:log:encrypt
run: .bin/infra deploy:log:encrypt
if: always()
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
Expand All @@ -91,15 +91,15 @@ jobs:

- name: Add Job summary
if: always()
run: echo 'You can get logs using `.bin/mna deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`' >> $GITHUB_STEP_SUMMARY
run: echo 'You can get logs using `.bin/infra deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`' >> $GITHUB_STEP_SUMMARY

- name: Notify failure on Slack
uses: ravsamhq/notify-slack-action@v2
if: always()
with:
status: ${{ job.status }}
notification_title: "Password rotate en ${{ inputs.product }}-${{ inputs.environment }} a échoué"
message_format: "{emoji} *[${{ inputs.product }}-${{ inputs.environment }}]* *{workflow}* {status_message} in <{repo_url}|{branch}> on <{commit_url}|{commit_sha}>. You can get error logs using `.bin/mna deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`"
message_format: "{emoji} *[${{ inputs.product }}-${{ inputs.environment }}]* *{workflow}* {status_message} in <{repo_url}|{branch}> on <{commit_url}|{commit_sha}>. You can get error logs using `.bin/infra deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`"
notify_when: "failure"
mention_groups: "!channel"
env:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/_reboot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
steps:
- name: Checkout project
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
Expand All @@ -70,14 +70,14 @@ jobs:
VAULT_PWD: ${{ secrets.VAULT_PWD }}

- name: Run playbook
run: ".bin/mna system:reboot ${{ inputs.product }} ${{ inputs.environment }}"
run: ".bin/infra system:reboot ${{ inputs.product }} ${{ inputs.environment }}"
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
ANSIBLE_REMOTE_USER: deploy
ANSIBLE_BECOME_PASS: ${{ secrets.DEPLOY_PASS }}

- name: Encrypt logs
run: .bin/mna deploy:log:encrypt
run: .bin/infra deploy:log:encrypt
if: always()
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
Expand All @@ -91,15 +91,15 @@ jobs:

- name: Add Job summary
if: always()
run: echo 'You can get logs using `.bin/mna deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`' >> $GITHUB_STEP_SUMMARY
run: echo 'You can get logs using `.bin/infra deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`' >> $GITHUB_STEP_SUMMARY

- name: Notify failure on Slack
uses: ravsamhq/notify-slack-action@v2
if: always()
with:
status: ${{ job.status }}
notification_title: "Reboot en ${{ inputs.product }}-${{ inputs.environment }} a échoué"
message_format: "{emoji} *[${{ inputs.product }}-${{ inputs.environment }}]* *{workflow}* {status_message} in <{repo_url}|{branch}> on <{commit_url}|{commit_sha}>. You can get error logs using `.bin/mna deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`"
message_format: "{emoji} *[${{ inputs.product }}-${{ inputs.environment }}]* *{workflow}* {status_message} in <{repo_url}|{branch}> on <{commit_url}|{commit_sha}>. You can get error logs using `.bin/infra deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`"
notify_when: "failure"
mention_groups: "!channel"
env:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
HABILITATIONS: ${{ secrets.HABILITATIONS }}

- name: Run playbook
run: ".bin/mna system:setup ${{ inputs.product }} ${{ inputs.environment }}"
run: ".bin/infra system:setup ${{ inputs.product }} ${{ inputs.environment }}"
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
ANSIBLE_REMOTE_USER: deploy
Expand All @@ -97,7 +97,7 @@ jobs:
APP_SECRET: ${{ secrets.OVH_APP_SECRET }}

- name: Encrypt logs
run: .bin/mna deploy:log:encrypt
run: .bin/infra deploy:log:encrypt
if: always()
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
Expand All @@ -111,15 +111,15 @@ jobs:

- name: Add Job summary
if: always()
run: echo 'You can get logs using `.bin/mna deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`' >> $GITHUB_STEP_SUMMARY
run: echo 'You can get logs using `.bin/infra deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`' >> $GITHUB_STEP_SUMMARY

- name: Notify failure on Slack
uses: ravsamhq/notify-slack-action@v2
if: always()
with:
status: ${{ job.status }}
notification_title: "Le setup ${{ inputs.product }} en ${{ inputs.environment }} a échoué"
message_format: "{emoji} *[${{ inputs.product }}-${{ inputs.environment }}]* *{workflow}* {status_message} in <{repo_url}|{branch}> on <{commit_url}|{commit_sha}>. You can get error logs using `.bin/mna deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`"
message_format: "{emoji} *[${{ inputs.product }}-${{ inputs.environment }}]* *{workflow}* {status_message} in <{repo_url}|{branch}> on <{commit_url}|{commit_sha}>. You can get error logs using `.bin/infra deploy:log:decrypt ${{ github.run_id }} ${{ inputs.product }}-${{ inputs.environment }}`"
notify_when: "failure"
mention_groups: "!channel"
env:
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/unban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ jobs:
strategy:
fail-fast: false
matrix:
product: ["api", "bal", "lba", "monitoring", "tdb", "vpn", "contrat", "data"]
product:
["api", "bal", "lba", "monitoring", "tdb", "vpn", "contrat", "data"]
environment: ["production", "recette", "preview", "pentest", "preprod"]
name: Unban ${{ inputs.ip }} on ${{ matrix.product }}-${{ matrix.environment }}
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
Expand All @@ -39,14 +40,14 @@ jobs:
VAULT_PWD: ${{ secrets.VAULT_PWD }}

- name: Run playbook
run: ".bin/mna system:unban ${{ matrix.product }} ${{ matrix.environment }} ${{ inputs.ip }}"
run: ".bin/infra system:unban ${{ matrix.product }} ${{ matrix.environment }} ${{ inputs.ip }}"
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
ANSIBLE_REMOTE_USER: deploy
ANSIBLE_BECOME_PASS: ${{ secrets.DEPLOY_PASS }}

- name: Encrypt logs
run: .bin/mna deploy:log:encrypt
run: .bin/infra deploy:log:encrypt
if: always()
env:
ANSIBLE_VAULT_PASSWORD_FILE: .infra/.vault_pwd.txt
Expand All @@ -60,15 +61,15 @@ jobs:

- name: Add Job summary
if: always()
run: echo 'You can get logs using `.bin/mna deploy:log:decrypt ${{ github.run_id }} ${{ matrix.product }}-${{ matrix.environment }}`' >> $GITHUB_STEP_SUMMARY
run: echo 'You can get logs using `.bin/infra deploy:log:decrypt ${{ github.run_id }} ${{ matrix.product }}-${{ matrix.environment }}`' >> $GITHUB_STEP_SUMMARY

- name: Notify failure on Slack
uses: ravsamhq/notify-slack-action@v2
if: always()
with:
status: ${{ job.status }}
notification_title: "Unban ip ${{ inputs.ip }} en ${{ matrix.product }}-${{ matrix.environment }} a échoué"
message_format: "{emoji} *[${{ matrix.product }}-${{ matrix.environment }}]* *{workflow}* {status_message} in <{repo_url}|{branch}> on <{commit_url}|{commit_sha}>. You can get error logs using `.bin/mna deploy:log:decrypt ${{ github.run_id }} ${{ matrix.product }}-${{ matrix.environment }}`"
message_format: "{emoji} *[${{ matrix.product }}-${{ matrix.environment }}]* *{workflow}* {status_message} in <{repo_url}|{branch}> on <{commit_url}|{commit_sha}>. You can get error logs using `.bin/infra deploy:log:decrypt ${{ github.run_id }} ${{ matrix.product }}-${{ matrix.environment }}`"
notify_when: "failure"
mention_groups: "!channel"
env:
Expand Down
8 changes: 5 additions & 3 deletions docs/manage_access.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Gestion des accès d'un produit

Donner accès à un produit revient à donner l'accès:

- aux **vault** d'un produit, la personne aura alors un accès à tous les secrets
- **root via SSH** aux different serveurs

## Mise à jour des habilitations

```bash
.bin/mna product:access:update <nom_produit>
.bin/infra product:access:update <nom_produit>
```

Un fichier vide s'ouvre dans VsCode, veuillez compléter les habilitations avec le model suivant:
Expand All @@ -18,7 +19,7 @@ habilitations:
name: "John Doe"
gpg_key: XXXXXX
authorized_keys:
- "https://github.com/mission-apprentissage.keys"
- "https://github.com/mission-apprentissage.keys"

gpg_keys: "{{ habilitations | map(attribute='gpg_key', default='') | select() | join(',')}}"
```
Expand All @@ -27,5 +28,6 @@ Fermez le fichier.
> [!WARNING]
> Les habilitations sont mise à jours, et stockées dans 1password. Par contre à ce stade elles ne sont pas appliquées, il faut pour cela:
>
> - lancer la configuration de l'environnement pour mettre à jour les accès SSH
> - ouvrir le vault du produit via `.bin/mna vault:edit` et commiter le changement du vault.
> - ouvrir le vault du produit via `.bin/infra vault:edit` et commiter le changement du vault.
12 changes: 6 additions & 6 deletions docs/provisionning.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Voir [Prérequis](./pre-requisites.md)
### Création du env.ini

```bash
.bin/mna product:create <nom_produit>
.bin/infra product:create <nom_produit>
```

Ouvrir le fichier `/products/<nom_produit>/env.ini` et mettre à jour les variables `product_name` & `repo`
Expand All @@ -42,7 +42,7 @@ Récupérez le slack webhook depuis https://api.slack.com/apps/A01JENR8874
Mettre à jour le vault

```bash
.bin/mna vault:edit
.bin/infra vault:edit
```

## Déclaration de l'environnement
Expand Down Expand Up @@ -75,9 +75,9 @@ Créer un domain name pour le nouvel environment https://admin.alwaysdata.com/re
Pour configurer l'environnement, il faut lancer la commande suivante :

```bash
.bin/mna ssh:known_hosts:update <nom_produit>
.bin/mna system:setup:initial <nom_produit> <nom_environnement>
.bin/mna ssh:config <nom_produit>
.bin/infra ssh:known_hosts:update <nom_produit>
.bin/infra system:setup:initial <nom_produit> <nom_environnement>
.bin/infra ssh:config <nom_produit>
```

L'utilisateur `ubuntu` est un utilisateur créé par défaut par OVH, le mot de passe de ce compte est envoyé par email à l'administrateur du compte OVH et est également disponible dans les emails de service : https://www.ovh.com/manager/dedicated/#/useraccount/emails
Expand All @@ -94,7 +94,7 @@ ssh <nom_produit>-<nom_environnement>
Enfin pour des questions de sécurité, vous devez supprimer l'utilisateur `ubuntu` :

```bash
.bin/mna system:user:remove <nom_produit> <nom_environnement> ubuntu --user <votre_nom_utilisateur>
.bin/infra system:user:remove <nom_produit> <nom_environnement> ubuntu --user <votre_nom_utilisateur>
```

## Mise à jour des Github Action
Expand Down

0 comments on commit a2676e9

Please sign in to comment.