Skip to content

Commit

Permalink
agent/local: only use agent token for deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed May 6, 2021
1 parent 0b017e2 commit 33d1a55
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions agent/local/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,15 @@ func (l *State) ServiceToken(id structs.ServiceID) string {
}

// aclTokenForServiceSync returns an ACL token associated with a service. If there is
// no ACL token associated with the service, falls back to the agent token, then to the
// user default token.
// no ACL token associated with the service, falls back to to the user default token.
// This method is not synchronized and the lock must already be held.
func (l *State) aclTokenForServiceSync(id structs.ServiceID) string {
var token string
if s := l.services[id]; s != nil {
token = s.Token
}
if token == "" {
token = l.tokens.AgentToken()
token = l.tokens.UserToken()
}
return token
}
Expand Down Expand Up @@ -457,8 +456,7 @@ func (l *State) CheckToken(id structs.CheckID) string {
}

// aclTokenForCheckSync returns an ACL token associated with a check. If there is
// no ACL token associated with the check, falls back to the agent token, then to the
// user default token.
// no ACL token associated with the check, falls back to the the user default token.
// This method is not synchronized and the lock must already be held.
func (l *State) aclTokenForCheckSync(id structs.CheckID) string {
var token string
Expand All @@ -467,7 +465,7 @@ func (l *State) aclTokenForCheckSync(id structs.CheckID) string {
token = c.Token
}
if token == "" {
token = l.tokens.AgentToken()
token = l.tokens.UserToken()
}
return token
}
Expand Down Expand Up @@ -1142,8 +1140,7 @@ func (l *State) deleteService(key structs.ServiceID) error {
return fmt.Errorf("ServiceID missing")
}

st := l.aclTokenForServiceSync(key)

st := l.tokens.AgentToken()
req := structs.DeregisterRequest{
Datacenter: l.config.Datacenter,
Node: l.config.NodeName,
Expand Down Expand Up @@ -1192,7 +1189,7 @@ func (l *State) deleteCheck(key structs.CheckID) error {
return fmt.Errorf("CheckID missing")
}

ct := l.aclTokenForCheckSync(key)
ct := l.tokens.AgentToken()
req := structs.DeregisterRequest{
Datacenter: l.config.Datacenter,
Node: l.config.NodeName,
Expand Down

0 comments on commit 33d1a55

Please sign in to comment.