mirror of
https://github.com/status-im/consul.git
synced 2025-02-23 10:58:25 +00:00
agent/local: only fallback to agent token for deletes
Fallback to the default user token for synching registrations.
This commit is contained in:
parent
aeaade3f29
commit
df5e18c9c5
@ -239,18 +239,13 @@ func (l *State) ServiceToken(id structs.ServiceID) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// aclTokenForServiceSync returns an ACL token associated with a service. If there is
|
// 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
|
// no ACL token associated with the service, fallback is used to return a value.
|
||||||
// user default token.
|
|
||||||
// This method is not synchronized and the lock must already be held.
|
// This method is not synchronized and the lock must already be held.
|
||||||
func (l *State) aclTokenForServiceSync(id structs.ServiceID) string {
|
func (l *State) aclTokenForServiceSync(id structs.ServiceID, fallback func() string) string {
|
||||||
var token string
|
if s := l.services[id]; s != nil && s.Token != "" {
|
||||||
if s := l.services[id]; s != nil {
|
return s.Token
|
||||||
token = s.Token
|
|
||||||
}
|
}
|
||||||
if token == "" {
|
return fallback()
|
||||||
token = l.tokens.AgentToken()
|
|
||||||
}
|
|
||||||
return token
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddService is used to add a service entry to the local state.
|
// AddService is used to add a service entry to the local state.
|
||||||
@ -457,19 +452,13 @@ func (l *State) CheckToken(id structs.CheckID) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// aclTokenForCheckSync returns an ACL token associated with a check. If there is
|
// 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
|
// no ACL token associated with the check, the callback is used to return a value.
|
||||||
// user default token.
|
|
||||||
// This method is not synchronized and the lock must already be held.
|
// This method is not synchronized and the lock must already be held.
|
||||||
func (l *State) aclTokenForCheckSync(id structs.CheckID) string {
|
func (l *State) aclTokenForCheckSync(id structs.CheckID, fallback func() string) string {
|
||||||
var token string
|
if c := l.checks[id]; c != nil && c.Token != "" {
|
||||||
c := l.checks[id]
|
return c.Token
|
||||||
if c != nil {
|
|
||||||
token = c.Token
|
|
||||||
}
|
}
|
||||||
if token == "" {
|
return fallback()
|
||||||
token = l.tokens.AgentToken()
|
|
||||||
}
|
|
||||||
return token
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCheck is used to add a health check to the local state.
|
// AddCheck is used to add a health check to the local state.
|
||||||
@ -1142,8 +1131,7 @@ func (l *State) deleteService(key structs.ServiceID) error {
|
|||||||
return fmt.Errorf("ServiceID missing")
|
return fmt.Errorf("ServiceID missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
st := l.aclTokenForServiceSync(key)
|
st := l.aclTokenForServiceSync(key, l.tokens.AgentToken)
|
||||||
|
|
||||||
req := structs.DeregisterRequest{
|
req := structs.DeregisterRequest{
|
||||||
Datacenter: l.config.Datacenter,
|
Datacenter: l.config.Datacenter,
|
||||||
Node: l.config.NodeName,
|
Node: l.config.NodeName,
|
||||||
@ -1192,7 +1180,7 @@ func (l *State) deleteCheck(key structs.CheckID) error {
|
|||||||
return fmt.Errorf("CheckID missing")
|
return fmt.Errorf("CheckID missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
ct := l.aclTokenForCheckSync(key)
|
ct := l.aclTokenForCheckSync(key, l.tokens.AgentToken)
|
||||||
req := structs.DeregisterRequest{
|
req := structs.DeregisterRequest{
|
||||||
Datacenter: l.config.Datacenter,
|
Datacenter: l.config.Datacenter,
|
||||||
Node: l.config.NodeName,
|
Node: l.config.NodeName,
|
||||||
@ -1236,7 +1224,7 @@ func (l *State) pruneCheck(id structs.CheckID) {
|
|||||||
|
|
||||||
// syncService is used to sync a service to the server
|
// syncService is used to sync a service to the server
|
||||||
func (l *State) syncService(key structs.ServiceID) error {
|
func (l *State) syncService(key structs.ServiceID) error {
|
||||||
st := l.aclTokenForServiceSync(key)
|
st := l.aclTokenForServiceSync(key, l.tokens.UserToken)
|
||||||
|
|
||||||
// If the service has associated checks that are out of sync,
|
// If the service has associated checks that are out of sync,
|
||||||
// piggyback them on the service sync so they are part of the
|
// piggyback them on the service sync so they are part of the
|
||||||
@ -1252,7 +1240,7 @@ func (l *State) syncService(key structs.ServiceID) error {
|
|||||||
if !key.Matches(c.Check.CompoundServiceID()) {
|
if !key.Matches(c.Check.CompoundServiceID()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if st != l.aclTokenForCheckSync(checkKey) {
|
if st != l.aclTokenForCheckSync(checkKey, l.tokens.UserToken) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
checks = append(checks, c.Check)
|
checks = append(checks, c.Check)
|
||||||
@ -1318,7 +1306,7 @@ func (l *State) syncService(key structs.ServiceID) error {
|
|||||||
// syncCheck is used to sync a check to the server
|
// syncCheck is used to sync a check to the server
|
||||||
func (l *State) syncCheck(key structs.CheckID) error {
|
func (l *State) syncCheck(key structs.CheckID) error {
|
||||||
c := l.checks[key]
|
c := l.checks[key]
|
||||||
ct := l.aclTokenForCheckSync(key)
|
ct := l.aclTokenForCheckSync(key, l.tokens.UserToken)
|
||||||
req := structs.RegisterRequest{
|
req := structs.RegisterRequest{
|
||||||
Datacenter: l.config.Datacenter,
|
Datacenter: l.config.Datacenter,
|
||||||
ID: l.config.NodeID,
|
ID: l.config.NodeID,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user