Skip to content
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
15 changes: 15 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
([Français](#code-de-conduite))

## Code of Conduct

Statistics Canada follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).

Please review before contributing issues, pull requests, or joining the GitHub organization.

______________________

## Code de conduite

Statistique Canada suit le [Code de conduite de la CNCF](https://github.com/cncf/foundation/blob/main/code-of-conduct-languages/fr.md).

Veuillez passer en revue avant de contribuer à des problèmes, des demandes d'extraction ou de rejoindre l'organisation GitHub.
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Contributing

([Français](#comment-contribuer))

## How to Contribute

When contributing, post comments and discuss changes you wish to make via Issues.

Feel free to propose changes by creating Pull Requests. If you don't have write access, editing a file will create a Fork of this project for you to save your proposed changes to. Submitting a change to a file will write it to a new Branch in your Fork, so you can send a Pull Request.

If this is your first time contributing on GitHub, don't worry! Let us know if you have any questions.

### Security

**Do not post any security issues on the public repository!** See [SECURITY.md](SECURITY.md)

______________________

## Comment contribuer

Lorsque vous contribuez, veuillez également publier des commentaires et discuter des modifications que vous souhaitez apporter par l'entremise des enjeux (Issues).

N'hésitez pas à proposer des modifications en créant des demandes de tirage (Pull Requests). Si vous n'avez pas accès au mode de rédaction, la modification d'un fichier créera une copie (Fork) de ce projet afin que vous puissiez enregistrer les modifications que vous proposez. Le fait de proposer une modification à un fichier l'écrira dans une nouvelle branche dans votre copie (Fork), de sorte que vous puissiez envoyer une demande de tirage (Pull Request).

Si c'est la première fois que vous contribuez à GitHub, ne vous en faites pas! Faites-nous part de vos questions.

### Sécurité

**Ne publiez aucun problème de sécurité sur le dépôt publique!** Voir [SECURITY.md](SECURITY.md)
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply the same correction here: use ‘dépôt public’ instead of ‘dépôt publique’.

Suggested change
**Ne publiez aucun problème de sécurité sur le dépôt publique!** Voir [SECURITY.md](SECURITY.md)
**Ne publiez aucun problème de sécurité sur le dépôt public!** Voir [SECURITY.md](SECURITY.md)

Copilot uses AI. Check for mistakes.
File renamed without changes.
173 changes: 141 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
# Kubernetes Namespace Cleaner

<p align="center">
<img src="https://github.com/user-attachments/assets/7f10d356-9312-4483-aea0-33aeef6880d9" alt="Namespace Cleaner Logo" width="400"/>
</p>
[(Français)](#nettoyeur-de-namespaces-kubernetes)

## Kubernetes Namespace Cleaner

A Kubernetes CronJob that automatically identifies and cleans up namespaces tied to deprovisioned Azure Entra ID (formerly Azure AD) users.
A Kubernetes CronJob that automatically detects and deletes namespaces associated with deprovisioned Azure Entra ID (formerly Azure AD) users.

## Development Status
### What is this project?

![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/StatCan/namespace-cleaner)
A lifecycle automation tool for Kubernetes namespaces. It identifies user-created namespaces, verifies user status through Azure Entra ID, and labels or deletes expired ones.

### How does it work?

It runs in two phases:

1. **Evaluation**: Identifies new namespaces and checks if the associated user is valid.
2. **Cleanup**: Deletes namespaces labeled for removal after a grace period, if the user is still missing.

It supports mock, dry-run, and production modes.

### Who will use this project?

Cluster administrators who need to enforce namespace hygiene and lifecycle policies in environments integrated with Entra ID, especially in multi-tenant Kubernetes platforms like Kubeflow.

### What is the goal of this project?

## Overview
To safely and automatically manage orphaned namespaces, reduce security risk, and maintain cluster cleanliness without manual intervention.

## System Overview

### Phase 1: New Namespace Evaluation (English)

### Phase 1: New Namespace Evaluation
```mermaid
flowchart TD
A[Start] --> B{Mode}
Expand All @@ -27,8 +44,8 @@ flowchart TD
G2 -->|Missing| I[Label for Deletion]
G2 -->|Exists| J[No Action]
```
### Phase 2: Expired Namespace Cleanup (English)

### Phase 2: Expired Namespace Cleanup
```mermaid
flowchart TD
K[Start] --> L[Check Labeled Namespaces]
Expand All @@ -38,40 +55,45 @@ flowchart TD
N -->|Yes| P[Delete Namespace]
N -->|No| Q[Remove Label]
```
## Key Features

## Features
- ✅ **Automated Lifecycle Management**: Label-based namespace management
- 🔒 **Security First**: Azure Entra ID integration with domain allowlisting
- 🧪 **Testing Friendly**: Local testing mode with mock data
- ☁️ **Safe Operations**: Dry-run capability for pre-deployment validation
* ✅ **Automated Lifecycle Management** – Label-based namespace retention system
* 🔒 **Security First** – Azure Entra ID user verification with domain allowlist
* 🧪 **Testing Friendly** – Mock and dry-run support
* ☁️ **Safe Operations** – Prevent accidental deletion through preview-only mode

## Quick Start

```bash
# Clone & Setup
git clone https://github.com/StatCan/namespace-cleaner.git
cd namespace-cleaner

# Build the Docker image (required for all other operations)
# Build the Docker image
make image

# Run unit tests
make test-unit

# Perform a dry-run on a real cluster
# Perform a dry-run (no real deletion)
make dry-run

# Deploy to production
# Deploy in production
make run
```

## CI/CD Integration
Our GitHub Actions workflow provides:
- ✅ Automatic test coverage tracking
- 🔒 Security scanning with Trivy
- 📦 Docker image builds on push
- 📈 Live coverage badge updates

Our GitHub Actions pipeline includes:

* ✅ Unit testing and dry-run validation
* 🔒 Trivy-based container image vulnerability scanning
* 📦 Docker builds on push
* 📈 Live test coverage badge generation


## Configuration

```yaml
# configmap.yaml
---
Expand All @@ -82,24 +104,111 @@ metadata:
namespace: das
data:
ALLOWED_DOMAINS: "statcan.gc.ca,cloud.statcan.ca"
GRACE_PERIOD: "90d" # Format: <number><unit> (h=hours, d=days)
GRACE_PERIOD: "90d" # e.g. "24h", "30d"
```

## Monitoring & Troubleshooting

```bash
# View logs
# View job logs
kubectl logs -l job-name=namespace-cleaner

# Check cronjob status
# View cronjob status
kubectl get cronjob namespace-cleaner -o wide

# Full system reset
# Reset everything
make stop && make clean && make run
```

## Contributing
1. Fork the repository
2. Create feature branch (`git checkout -b feature/your-feature`)
3. Commit changes with tests (`make test`)
4. Push to branch (`git push origin feature/your-feature`)
5. Open PR with coverage badge verification
### Development Status

![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/StatCan/namespace-cleaner)

### How to Contribute

See [CONTRIBUTING.md](CONTRIBUTING.md)

### License

Unless otherwise noted, the source code of this project is covered under Crown Copyright, Government of Canada, and is distributed under the [GNU Affero General Public License](LICENSE).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, no suggestion, just a happy comment :)


The Canada wordmark and related graphics associated with this distribution are protected under trademark law and copyright law. No permission is granted to use them outside the parameters of the Government of Canada's corporate identity program. For more information, see [Federal identity requirements](https://www.canada.ca/en/treasury-board-secretariat/topics/government-communications/federal-identity-requirements.html).

---

## Nettoyeur de Namespaces Kubernetes

[(English)](#kubernetes-namespace-cleaner)

### Quel est ce projet?

Un CronJob Kubernetes qui détecte et supprime automatiquement les espaces de noms associés aux utilisateurs Azure Entra ID (anciennement Azure AD) déprovisionnés.

### Comment ça marche?

Le CronJob fonctionne en deux phases :

1. **Évaluation** : identifie les nouveaux espaces de noms et vérifie si l'utilisateur associé est valide.
2. **Nettoyage** : supprime les espaces de noms étiquetés pour suppression après un délai de grâce, si l'utilisateur est toujours inexistant.

Trois modes sont disponibles : test, simulation (dry-run) et production.

### Qui utilisera ce projet?

Les administrateurs de clusters Kubernetes dans des environnements partagés (tel que Kubeflow), intégrés avec Entra ID.

### Quel est le but de ce projet?

Réduire les risques de sécurité et garder un cluster propre grâce à la gestion automatique du cycle de vie des espaces de noms.

---

#### Comment contribuer

Voir [CONTRIBUTING.md](CONTRIBUTING.md)

---

#### Licence

Sauf indication contraire, le code source de ce projet est protégé par le droit d'auteur de la Couronne du gouvernement du Canada et distribué sous la [licence publique générale affero GNU](LICENSE).

Le mot-symbole « Canada » et les éléments graphiques connexes liés à cette distribution sont protégés en vertu des lois portant sur les marques de commerce et le droit d'auteur. Aucune autorisation n'est accordée pour leur utilisation à l'extérieur des paramètres du programme de coordination de l'image de marque du gouvernement du Canada. Pour obtenir davantage de renseignements à ce sujet, veuillez consulter les [Exigences pour l'image de marque](https://www.canada.ca/fr/secretariat-conseil-tresor/sujets/communications-gouvernementales/exigences-image-marque.html).

---

### Phase 1: Évaluation des nouveaux namespaces (Français)

```mermaid
flowchart TD
A[Début] --> B{Mode}
B -->|Test| C[Utiliser des données simulées]
B -->|Simulation| D[Afficher les actions]
B -->|Production| E[Authentification Azure réelle]
C & D & E --> F[Analyser les nouveaux espaces de noms]
F --> G1{Domaine valide ?}
G1 -->|Oui| G2{Utilisateur existant ?}
G1 -->|Non| H[Consigner et ignorer]
G2 -->|Inexistant| I[Étiqueter pour suppression]
G2 -->|Existant| J[Aucune action]
```

### Phase 2 : Nettoyage des espaces de noms expirés (Français)

```mermaid
flowchart TD
K[Début] --> L[Analyser les espaces de noms étiquetés]
L --> M{Délai de grâce expiré ?}
M -->|Oui| N{Utilisateur toujours inexistant ?}
M -->|Non| O[Garder l'espace de noms]
N -->|Oui| P[Supprimer l'espace de noms]
N -->|Non| Q[Retirer l'étiquette]
```

## Fonctionnalités principales

* ✅ **Gestion automatisée du cycle de vie** – Système de conservation basé sur des étiquettes
* 🔒 **Sécurité avant tout** – Vérification des utilisateurs avec Entra ID et liste de domaines autorisés
* 🧪 **Tests facilités** – Prise en charge des modes test et simulation
* ☁️ **Sécurité des opérations** – Empêche les suppressions accidentelles grâce au mode aperçu

11 changes: 11 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
([Français](#sécurité))

# Security

**Do not post any security issues on the public repository!** Security vulnerabilities must be reported by email to `statcan.cybersecurity-cybersecurite.statcan@statcan.gc.ca`

______________________

## Sécurité

**Ne publiez aucun problème de sécurité sur le dépôt publique!** Les vulnérabilités de sécurité doivent être signalées par courriel à `statcan.cybersecurity-cybersecurite.statcan@statcan.gc.ca`
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In French, ‘dépôt’ is masculine, so the adjective should be ‘public’ rather than ‘publique’.

Suggested change
**Ne publiez aucun problème de sécurité sur le dépôt publique!** Les vulnérabilités de sécurité doivent être signalées par courriel à `statcan.cybersecurity-cybersecurite.statcan@statcan.gc.ca`
**Ne publiez aucun problème de sécurité sur le dépôt public!** Les vulnérabilités de sécurité doivent être signalées par courriel à `statcan.cybersecurity-cybersecurite.statcan@statcan.gc.ca`

Copilot uses AI. Check for mistakes.
Loading