This commit is contained in:
@@ -92,6 +92,7 @@ CONFIG_FILE="/etc/teleport.yaml"
|
|||||||
# Edit the teleport.yaml file to update the nodename
|
# Edit the teleport.yaml file to update the nodename
|
||||||
sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" "$CONFIG_FILE"
|
sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" "$CONFIG_FILE"
|
||||||
|
|
||||||
|
# Function to add labels to teleport.yaml
|
||||||
# Function to add labels to teleport.yaml
|
# Function to add labels to teleport.yaml
|
||||||
add_teleport_labels() {
|
add_teleport_labels() {
|
||||||
if [ -n "$TELEPORT_LABELS" ]; then
|
if [ -n "$TELEPORT_LABELS" ]; then
|
||||||
@@ -103,14 +104,12 @@ add_teleport_labels() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove any existing labels section
|
# Create a backup
|
||||||
sed -i '/^ labels:/,/^[^[:space:]]/ { /^ labels:/d; /^[^[:space:]]/!d; }' "$CONFIG_FILE"
|
cp "$CONFIG_FILE" "$CONFIG_FILE.backup"
|
||||||
|
|
||||||
# Find the line number of ssh_service and add labels after it
|
# Build the new ssh_service section
|
||||||
ssh_line=$(grep -n "^ssh_service:" "$CONFIG_FILE" | cut -d: -f1)
|
NEW_SSH_SECTION="ssh_service:"
|
||||||
|
NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" labels:"
|
||||||
# Add labels section after ssh_service
|
|
||||||
sed -i "${ssh_line}a\\ labels:" "$CONFIG_FILE"
|
|
||||||
|
|
||||||
# Parse TELEPORT_LABELS and add each label
|
# Parse TELEPORT_LABELS and add each label
|
||||||
IFS=',' read -ra LABELS <<< "$TELEPORT_LABELS"
|
IFS=',' read -ra LABELS <<< "$TELEPORT_LABELS"
|
||||||
@@ -124,7 +123,7 @@ add_teleport_labels() {
|
|||||||
value=$(echo "$label" | cut -d':' -f2- | xargs)
|
value=$(echo "$label" | cut -d':' -f2- | xargs)
|
||||||
|
|
||||||
if [ -n "$key" ] && [ -n "$value" ]; then
|
if [ -n "$key" ] && [ -n "$value" ]; then
|
||||||
echo " $key: $value" >> "$CONFIG_FILE"
|
NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" $key: $value"
|
||||||
echo "Added label: $key = $value"
|
echo "Added label: $key = $value"
|
||||||
else
|
else
|
||||||
echo "Warning: Invalid label format '$label'. Expected format: key:value"
|
echo "Warning: Invalid label format '$label'. Expected format: key:value"
|
||||||
@@ -134,6 +133,36 @@ add_teleport_labels() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" enabled: \"yes\""
|
||||||
|
|
||||||
|
# Replace the ssh_service section
|
||||||
|
awk -v new_section="$NEW_SSH_SECTION" '
|
||||||
|
BEGIN {
|
||||||
|
in_ssh_service = 0
|
||||||
|
section_replaced = 0
|
||||||
|
}
|
||||||
|
/^ssh_service:/ {
|
||||||
|
in_ssh_service = 1
|
||||||
|
if (!section_replaced) {
|
||||||
|
print new_section
|
||||||
|
section_replaced = 1
|
||||||
|
}
|
||||||
|
next
|
||||||
|
}
|
||||||
|
in_ssh_service && /^[a-zA-Z_][a-zA-Z0-9_]*:/ {
|
||||||
|
in_ssh_service = 0
|
||||||
|
}
|
||||||
|
in_ssh_service {
|
||||||
|
next
|
||||||
|
}
|
||||||
|
{
|
||||||
|
print $0
|
||||||
|
}
|
||||||
|
' "$CONFIG_FILE" > "$CONFIG_FILE.tmp"
|
||||||
|
|
||||||
|
# Replace the original file
|
||||||
|
mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
|
||||||
|
|
||||||
echo "Teleport labels added successfully"
|
echo "Teleport labels added successfully"
|
||||||
else
|
else
|
||||||
echo "No TELEPORT_LABELS environment variable set, skipping label configuration"
|
echo "No TELEPORT_LABELS environment variable set, skipping label configuration"
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
4.0
|
4.1
|
||||||
Reference in New Issue
Block a user