-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9de852
commit 5977255
Showing
37 changed files
with
341 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Installation Guide for tconfigd | ||
|
||
## Prerequisites | ||
- **Kubernetes Cluster**: Ensure your Kubernetes cluster is active and accessible. | ||
- **kubectl**: Confirm `kubectl` is installed and configured to interact with your Kubernetes cluster. | ||
|
||
## Installation Steps | ||
|
||
tconfigd requires SPIRE for its operation. If your infrastructure already has SPIRE installed, follow the [instructions for environments with existing SPIRE](#environment-with-existing-spire-installation) to install tconfigd. If SPIRE is not present, the steps below will include its installation as part of the tconfigd setup. | ||
|
||
|
||
### 1. Clone the Repository | ||
Clone the tconfigd repository and navigate to the installation directory: | ||
|
||
```bash | ||
git clone https://github.com/tratteria/tconfigd.git | ||
``` | ||
|
||
```bash | ||
cd tconfigd/installation | ||
``` | ||
|
||
Alternatively, perform a shallow clone of just the installation subdirectory. | ||
|
||
|
||
### 2. Configure tconfigd | ||
|
||
Update the `config.yaml` file to match your specific deployment settings: | ||
|
||
- **Configure the settings as described below:** | ||
- `enableTratInterception`: "`true`" | ||
- **Description**: Set to "`true`" to enable interception of incoming requests for TraT verification. Set to "`false`" if using the [delegation method](https://github.com/tratteria/tratteria-agent) for TraT verification. | ||
- `agentApiPort`: "`9040`" | ||
- **Description**: The port number for the tratteria agent API. Do not change this unless you have some specific need. | ||
- `agentInterceptorPort`: "`9050`" | ||
- **Description**: The port number for the tratteria agent's incoming requests interceptor. Do not change this unless you have some specific need. | ||
- `spiffeEndpointSocket`: "`unix:///run/spire/sockets/agent.sock`" | ||
- **Description**: Path to the SPIFFE Workload API Unix socket. Do not change this if you are using the tconfigd SPIRE installation. | ||
- `tconfigdSpiffeId`: "`spiffe://tratteria.io/tconfigd`" | ||
- **Description**: SPIFFE ID for tconfigd. Do not change this if you are using the tconfigd SPIRE installation. | ||
|
||
|
||
### 3. Run the Installation Script | ||
|
||
Deploy the tconfigd to your Kubernetes cluster by running the installation script: | ||
|
||
```bash | ||
./install.sh | ||
``` | ||
|
||
### 4. Verification | ||
|
||
Verify the installation by checking the status of the tconfigd pod in the `tratteria-system` namespace. Use the following command to view the pod: | ||
|
||
```bash | ||
kubectl get pods -n tratteria-system | ||
``` | ||
|
||
For a practical example of installing tconfigd on a microservice application, refer to the [example-application](https://github.com/tratteria/example-application). | ||
|
||
## Environment with Existing SPIRE Installation | ||
If you already have SPIRE installed, follow these steps to install tconfigd: | ||
|
||
### 1. Register tconfigd with your running SPIRE: | ||
Below is a sample registartion command: | ||
|
||
```bash | ||
kubectl exec -n spire spire-server-0 -- \ | ||
/opt/spire/bin/spire-server entry create --dns tconfigd tratteria-system.svc \ | ||
-spiffeID spiffe://<your-trust-domain>/tconfigd \ | ||
-parentID spiffe://<your-trust-domain>/ns/spire/sa/spire-agent \ | ||
-selector k8s:ns:tratteria-system \ | ||
-selector k8s:sa:tconfigd-service-account | ||
``` | ||
|
||
### 2. Clone the tconfig Repository: | ||
|
||
Follow the [instructions to clone the repository](#1-clone-the-repository) from the general installation guide. | ||
|
||
### 3. Configure tconfigd: | ||
|
||
Adjust the following fields in your `config.yaml` file to align with your SPIRE settings. | ||
|
||
```yaml | ||
spiffeEndpointSocket: "unix:///run/spire/sockets/agent.sock" # Path to the SPIFFE Workload API Unix socket, replace this if your installation settings differ. | ||
tconfigdSpiffeId: "spiffe://<trust-domain>/tconfigd" # SPIFFE ID used in the registration command above. | ||
``` | ||
For configuring other fields, refer to the [general installation configuration guide above](#2-configure-tconfigd). | ||
### 4. Run the Installation Script: | ||
When installing tconfigd, add the `--no-spire` flag to the installation script to prevent reinstalling SPIRE in your environment. Similarly, use this flag when running the uninstallation script to keep SPIRE intact. | ||
|
||
```bash | ||
./install.sh --no-spire | ||
``` | ||
|
||
### 5. Verify Installation: | ||
|
||
Follow the [verification steps](#4-verification) provided in the general installation guide. | ||
|
||
For a practical example of installing tconfigd on a microservice application with existing SPIRE setup, refer to the [example-application-with-existing-spire](https://github.com/tratteria/example-application-with-existing-spire). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enableTratInterception: "true" # Enable or disable incoming requests interception for TraT verification | ||
agentApiPort: "9040" # Port number for the tratteria agent API | ||
agentInterceptorPort: "9050" # Port number for the tratteria agent incoming requests interceptor | ||
spiffeEndpointSocket: "unix:///run/spire/sockets/agent.sock" # Don't change this if you are using tconfigd SPIRE installation | ||
tconfigdSpiffeId: "spiffe://tratteria.io/tconfigd" # Don't change this if you are using tconfigd SPIRE installation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/bin/bash | ||
|
||
info() { | ||
printf "\e[34m%s\n\e[0m" "$1" | ||
} | ||
|
||
error() { | ||
printf "\e[31m%s\n\e[0m" "$1" | ||
} | ||
|
||
success() { | ||
printf "\e[32m%s\n\e[0m" "$1" | ||
} | ||
|
||
usage() { | ||
echo "Usage: $0 [OPTIONS]" | ||
echo "Options:" | ||
echo " --no-spire Skips the installation of SPIRE." | ||
echo " -h, --help Displays this help message." | ||
} | ||
|
||
apply_k8s_config() { | ||
kubectl apply -f $1 || { error "Failed to apply configuration for $1"; exit 1; } | ||
} | ||
|
||
validate_resource() { | ||
resource_type=$1 | ||
resource_name=$2 | ||
if ! kubectl get ${resource_type} ${resource_name} -n tratteria-system > /dev/null 2>&1; then | ||
error "${resource_type} ${resource_name} is not configured properly." | ||
exit 1 | ||
fi | ||
} | ||
|
||
install_spire=true | ||
|
||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
--no-spire) install_spire=false ;; | ||
-h|--help) usage; exit 0 ;; | ||
*) echo "Unknown option: $1"; usage; exit 1 ;; | ||
esac | ||
shift | ||
done | ||
|
||
if kubectl get namespace tratteria-system > /dev/null 2>&1; then | ||
error "tconfigd is already installed. Please uninstall the existing installation before proceeding." | ||
exit 1 | ||
fi | ||
|
||
if [ "$install_spire" = true ]; then | ||
cd resources/spire | ||
chmod +x install.sh | ||
./install.sh | ||
cd ../../ | ||
fi | ||
|
||
info "Installing tconfigd..." | ||
|
||
apply_k8s_config resources/namespaces.yaml | ||
apply_k8s_config resources/crds | ||
apply_k8s_config resources/service-account.yaml | ||
apply_k8s_config resources/role.yaml | ||
apply_k8s_config resources/rolebinding.yaml | ||
apply_k8s_config resources/deployment.yaml | ||
apply_k8s_config resources/service.yaml | ||
apply_k8s_config resources/tratteria-agent-injector-mutating-webhook.yaml | ||
|
||
kubectl create configmap config --from-file=config.yaml=config.yaml -n tratteria-system || { | ||
error "Failed to create static configuration config map" | ||
exit 1 | ||
} | ||
|
||
info "Checking for the readiness of tconfigd..." | ||
attempts=0 | ||
max_attempts=5 | ||
while ! kubectl get pods -n tratteria-system | grep -q '1/1.*Running'; do | ||
if [ $attempts -ge $max_attempts ]; then | ||
error "Failed to verify the readiness of tconfigd." | ||
exit 1 | ||
fi | ||
attempts=$((attempts + 1)) | ||
info "Waiting for tconfigd to be ready..." | ||
sleep 10 | ||
done | ||
|
||
validate_resource namespace tratteria-system | ||
validate_resource crd trats.tratteria.io | ||
validate_resource crd tratteriaconfigs.tratteria.io | ||
validate_resource serviceaccount tconfigd-service-account | ||
validate_resource clusterrole tconfigd-service-account-role | ||
validate_resource clusterrolebinding tconfigd-service-account-binding | ||
validate_resource deployment tconfigd | ||
validate_resource service tconfigd | ||
validate_resource mutatingwebhookconfiguration tratteria-agent-injector | ||
|
||
success "tconfigd installation completed successfully." |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: List | ||
items: | ||
- apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: tratteria-system |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: List | ||
items: | ||
- apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: spire |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
|
||
info() { | ||
printf "\e[34m%s\n\e[0m" "$1" | ||
} | ||
|
||
error() { | ||
printf "\e[31m%s\n\e[0m" "$1" | ||
} | ||
|
||
success() { | ||
printf "\e[32m%s\n\e[0m" "$1" | ||
} | ||
|
||
usage() { | ||
echo "Usage: $0 [OPTIONS]" | ||
echo "Options:" | ||
echo " --no-spire Skips the uninstallation of SPIRE." | ||
echo " -h, --help Displays this help message." | ||
} | ||
|
||
resource_exists() { | ||
resource_type=$1 | ||
resource_name=$2 | ||
kubectl get ${resource_type} ${resource_name} > /dev/null 2>&1 | ||
} | ||
|
||
delete_k8s_resource() { | ||
resource_type=$1 | ||
resource_name=$2 | ||
if resource_exists ${resource_type} ${resource_name}; then | ||
kubectl delete ${resource_type} ${resource_name} || { error "Failed to delete ${resource_type} ${resource_name}"; exit 1; } | ||
else | ||
info "${resource_type} ${resource_name} does not exist, skipping deletion." | ||
fi | ||
} | ||
|
||
uninstall_spire=true | ||
|
||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
--no-spire) uninstall_spire=false ;; | ||
-h|--help) usage; exit 0 ;; | ||
*) echo "Unknown option: $1"; usage; exit 1 ;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ "$uninstall_spire" = true ]; then | ||
info "Uninstalling spire..." | ||
cd resources/spire | ||
chmod +x uninstall.sh | ||
./uninstall.sh | ||
cd ../../ | ||
fi | ||
|
||
info "Uninstalling tconfigd..." | ||
|
||
delete_k8s_resource namespace tratteria-system | ||
delete_k8s_resource clusterrole tconfigd-service-account-role | ||
delete_k8s_resource clusterrolebinding tconfigd-service-account-binding | ||
delete_k8s_resource mutatingwebhookconfiguration tratteria-agent-injector | ||
delete_k8s_resource crd trats.tratteria.io | ||
delete_k8s_resource crd tratteriaconfigs.tratteria.io | ||
|
||
success "tconfigd uninstalled successfully." |
Oops, something went wrong.