Skip to content
Open
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
72 changes: 72 additions & 0 deletions pkg/tkn/host_access_secret_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package tkn

import (
"bufio"
"os"
"path/filepath"
"strings"
"testing"
)

func TestAWSHostAccessSecretEncoding(t *testing.T) {
root := moduleRoot(t)

for _, dir := range []string{"tkn", filepath.Join("tkn", "template")} {
entries, err := os.ReadDir(filepath.Join(root, dir))
if err != nil {
t.Fatal(err)
}
for _, entry := range entries {
name := entry.Name()
if !strings.HasPrefix(name, "infra-aws-") || !strings.HasSuffix(name, ".yaml") {
continue
}
checkFile(t, filepath.Join(root, dir, name))
}
}
}

func checkFile(t *testing.T, path string) {
t.Helper()

f, err := os.Open(path)
if err != nil {
t.Fatal(err)
}
defer f.Close()

Check failure on line 36 in pkg/tkn/host_access_secret_test.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `f.Close` is not checked (errcheck)

sc := bufio.NewScanner(f)
for sc.Scan() {
line := sc.Text()
if !strings.Contains(line, "$(cat /opt/host-info/") {
continue
}
if strings.Contains(line, "id_rsa:") {
if strings.Contains(line, "tr -d") {
t.Errorf("%s: id_rsa must not use tr -d: %s", path, strings.TrimSpace(line))
}
continue
}
if !strings.Contains(line, `tr -d '\n\r'`) {
t.Errorf("%s: host/username must use tr -d: %s", path, strings.TrimSpace(line))
}
}
if err := sc.Err(); err != nil {
t.Fatal(err)
}
}

func moduleRoot(t *testing.T) string {
t.Helper()
dir, _ := os.Getwd()
for {
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
return dir
}
parent := filepath.Dir(dir)
if parent == dir {
t.Fatal("go.mod not found")
}
dir = parent
}
}
8 changes: 4 additions & 4 deletions tkn/infra-aws-fedora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,14 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF
if [[ "$(params.airgap)" == "true" ]]; then
cat <<EOF >> host-info.yaml
bastion-host: $(cat /opt/host-info/bastion_host | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | base64 -w0)
bastion-host: $(cat /opt/host-info/bastion_host | tr -d '\n\r' | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | tr -d '\n\r' | base64 -w0)
bastion-id_rsa: $(cat /opt/host-info/bastion_id_rsa | base64 -w0)
EOF
fi
Expand Down
8 changes: 4 additions & 4 deletions tkn/infra-aws-mac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,14 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF
if [[ $(params.airgap) == "true" ]]; then
cat <<EOF >> host-info.yaml
bastion-host: $(cat /opt/host-info/bastion_host | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | base64 -w0)
bastion-host: $(cat /opt/host-info/bastion_host | tr -d '\n\r' | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | tr -d '\n\r' | base64 -w0)
bastion-id_rsa: $(cat /opt/host-info/bastion_id_rsa | base64 -w0)
EOF
fi
Expand Down
4 changes: 2 additions & 2 deletions tkn/infra-aws-rhel-ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF

Expand Down
8 changes: 4 additions & 4 deletions tkn/infra-aws-rhel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF
if [[ "$(params.airgap)" == "true" ]]; then
cat <<EOF >> host-info.yaml
bastion-host: $(cat /opt/host-info/bastion_host | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | base64 -w0)
bastion-host: $(cat /opt/host-info/bastion_host | tr -d '\n\r' | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | tr -d '\n\r' | base64 -w0)
bastion-id_rsa: $(cat /opt/host-info/bastion_id_rsa | base64 -w0)
EOF
fi
Expand Down
8 changes: 4 additions & 4 deletions tkn/infra-aws-windows-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,14 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF
if [[ $(params.airgap) == "true" ]]; then
cat <<EOF >> host-info.yaml
bastion-host: $(cat /opt/host-info/bastion_host | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | base64 -w0)
bastion-host: $(cat /opt/host-info/bastion_host | tr -d '\n\r' | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | tr -d '\n\r' | base64 -w0)
bastion-id_rsa: $(cat /opt/host-info/bastion_id_rsa | base64 -w0)
EOF
fi
Expand Down
8 changes: 4 additions & 4 deletions tkn/template/infra-aws-fedora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,14 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF
if [[ "$(params.airgap)" == "true" ]]; then
cat <<EOF >> host-info.yaml
bastion-host: $(cat /opt/host-info/bastion_host | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | base64 -w0)
bastion-host: $(cat /opt/host-info/bastion_host | tr -d '\n\r' | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | tr -d '\n\r' | base64 -w0)
bastion-id_rsa: $(cat /opt/host-info/bastion_id_rsa | base64 -w0)
EOF
fi
Expand Down
8 changes: 4 additions & 4 deletions tkn/template/infra-aws-mac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,14 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF
if [[ $(params.airgap) == "true" ]]; then
cat <<EOF >> host-info.yaml
bastion-host: $(cat /opt/host-info/bastion_host | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | base64 -w0)
bastion-host: $(cat /opt/host-info/bastion_host | tr -d '\n\r' | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | tr -d '\n\r' | base64 -w0)
bastion-id_rsa: $(cat /opt/host-info/bastion_id_rsa | base64 -w0)
EOF
fi
Expand Down
4 changes: 2 additions & 2 deletions tkn/template/infra-aws-rhel-ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF

Expand Down
8 changes: 4 additions & 4 deletions tkn/template/infra-aws-rhel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF
if [[ "$(params.airgap)" == "true" ]]; then
cat <<EOF >> host-info.yaml
bastion-host: $(cat /opt/host-info/bastion_host | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | base64 -w0)
bastion-host: $(cat /opt/host-info/bastion_host | tr -d '\n\r' | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | tr -d '\n\r' | base64 -w0)
bastion-id_rsa: $(cat /opt/host-info/bastion_id_rsa | base64 -w0)
EOF
fi
Expand Down
8 changes: 4 additions & 4 deletions tkn/template/infra-aws-windows-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,14 @@ spec:
cat <<EOF >> host-info.yaml
type: Opaque
data:
host: $(cat /opt/host-info/host | base64 -w0)
username: $(cat /opt/host-info/username | base64 -w0)
host: $(cat /opt/host-info/host | tr -d '\n\r' | base64 -w0)
username: $(cat /opt/host-info/username | tr -d '\n\r' | base64 -w0)
id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
EOF
if [[ $(params.airgap) == "true" ]]; then
cat <<EOF >> host-info.yaml
bastion-host: $(cat /opt/host-info/bastion_host | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | base64 -w0)
bastion-host: $(cat /opt/host-info/bastion_host | tr -d '\n\r' | base64 -w0)
bastion-username: $(cat /opt/host-info/bastion_username | tr -d '\n\r' | base64 -w0)
bastion-id_rsa: $(cat /opt/host-info/bastion_id_rsa | base64 -w0)
EOF
fi
Expand Down
Loading