-
Notifications
You must be signed in to change notification settings - Fork 492
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
Enable agent path template customization for azure_msi node attestor plugin #3488
Changes from all commits
d47c456
c799d2c
feb7c06
b2288d1
81a64ae
6c27162
054c361
4077887
d9c540f
430a6c6
3066e24
5cef0ef
7575ad5
ab6f893
327af58
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 |
---|---|---|
|
@@ -5,9 +5,10 @@ import ( | |
"encoding/json" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"path" | ||
|
||
"github.com/spiffe/go-spiffe/v2/spiffeid" | ||
"github.com/spiffe/spire/pkg/common/agentpathtemplate" | ||
"github.com/spiffe/spire/pkg/common/idutil" | ||
"github.com/zeebo/errs" | ||
"gopkg.in/square/go-jose.v2/jwt" | ||
) | ||
|
@@ -17,8 +18,12 @@ const ( | |
// audience of the MSI token. The current value is the service ID for the | ||
// Resource Manager API. | ||
DefaultMSIResourceID = "https://management.azure.com/" | ||
PluginName = "azure_msi" | ||
) | ||
|
||
// DefaultAgentPathTemplate is the default text/template | ||
var DefaultAgentPathTemplate = agentpathtemplate.MustParse("/{{ .PluginName }}/{{ .TenantID }}/{{ .PrincipalID }}") | ||
|
||
type ComputeMetadata struct { | ||
Name string `json:"name"` | ||
SubscriptionID string `json:"subscriptionId"` | ||
|
@@ -35,16 +40,8 @@ type MSIAttestationData struct { | |
|
||
type MSITokenClaims struct { | ||
jwt.Claims | ||
TenantID string `json:"tid,omitempty"` | ||
} | ||
|
||
func (c *MSITokenClaims) AgentID(trustDomain string) string { | ||
u := url.URL{ | ||
Scheme: "spiffe", | ||
Host: trustDomain, | ||
Path: path.Join("spire", "agent", "azure_msi", c.TenantID, c.Subject), | ||
} | ||
return u.String() | ||
TenantID string `json:"tid,omitempty"` | ||
PrincipalID string `json:"sub,omitempty"` | ||
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. I did a double take and had to remind myself what happens with the JSON decoder when there are two fields with the same tag. Fortunately the top level field takes precedence over the embedded struct but this is going to be a little subtle if there is any code that tries to use the 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. I thought about creating a new struct for only storing claims/fields that we want to expose and use. But we would still have another struct being composed by 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. I think we're ok with it as-is. If the |
||
} | ||
|
||
type HTTPClient interface { | ||
|
@@ -125,6 +122,23 @@ func FetchInstanceMetadata(ctx context.Context, cl HTTPClient) (*InstanceMetadat | |
return metadata, nil | ||
} | ||
|
||
type agentPathTemplateData struct { | ||
MSITokenClaims | ||
PluginName string | ||
} | ||
|
||
func MakeAgentID(td spiffeid.TrustDomain, agentPathTemplate *agentpathtemplate.Template, claims *MSITokenClaims) (spiffeid.ID, error) { | ||
agentPath, err := agentPathTemplate.Execute(agentPathTemplateData{ | ||
MSITokenClaims: *claims, | ||
PluginName: PluginName, | ||
}) | ||
if err != nil { | ||
return spiffeid.ID{}, err | ||
} | ||
|
||
return idutil.AgentID(td, agentPath) | ||
} | ||
|
||
func tryRead(r io.Reader) string { | ||
b := make([]byte, 1024) | ||
n, _ := r.Read(b) | ||
|
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.
can you update server_full.conf, with this new configuration?
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.
Sure!