-
Notifications
You must be signed in to change notification settings - Fork 0
Make the SPIFFE socket configurable #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||
| "log" | ||||||||||||||||||||||||||||||||||||
| "log/slog" | ||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
@@ -21,16 +22,23 @@ import ( | |||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const ( | ||||||||||||||||||||||||||||||||||||
| apiTimeout = 5 * time.Second | ||||||||||||||||||||||||||||||||||||
| spiffeSocket = "unix:///spiffe-workload-api/spire-agent.sock" | ||||||||||||||||||||||||||||||||||||
| timeFormat = time.RFC3339 | ||||||||||||||||||||||||||||||||||||
| apiTimeout = 5 * time.Second | ||||||||||||||||||||||||||||||||||||
| defaultSpiffeSocket = "unix:///spiffe-workload-api/spire-agent.sock" | ||||||||||||||||||||||||||||||||||||
| timeFormat = time.RFC3339 | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| func main() { | ||||||||||||||||||||||||||||||||||||
| ctx, cancel := context.WithTimeout(context.Background(), apiTimeout) | ||||||||||||||||||||||||||||||||||||
| defer cancel() | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| client, err := workloadapi.New(ctx, workloadapi.WithAddr(spiffeSocket), workloadapi.WithLogger(logger.Std)) | ||||||||||||||||||||||||||||||||||||
| // Get socket path from environment variable, with a fallback to the default. | ||||||||||||||||||||||||||||||||||||
| // SPIFFE_ENDPOINT_SOCKET is the standard environment variable for this. | ||||||||||||||||||||||||||||||||||||
| socketPath := os.Getenv("SPIFFE_ENDPOINT_SOCKET") | ||||||||||||||||||||||||||||||||||||
| if socketPath == "" { | ||||||||||||||||||||||||||||||||||||
| socketPath = defaultSpiffeSocket | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| client, err := workloadapi.New(ctx, workloadapi.WithAddr(socketPath), workloadapi.WithLogger(logger.Std)) | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better debuggability, it would be helpful to log which socket path is being used to connect to the SPIFFE Workload API. Since this is a debug container, having this information in the logs can be very valuable. This can be done by adding a single log line after determining the socket path.
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||
| log.Fatalf("Unable to create workload API client: %v", err) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think go-spiffe automatically reads this env var.