self.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package ipnauth
  4. import (
  5. "context"
  6. "tailscale.com/ipn"
  7. )
  8. // Self is a caller identity that represents the tailscaled itself and therefore
  9. // has unlimited access.
  10. var Self Actor = unrestricted{}
  11. // TODO is a caller identity used when the operation is performed on behalf of a user,
  12. // rather than by tailscaled itself, but the surrounding function is not yet extended
  13. // to accept an [Actor] parameter. It grants the same unrestricted access as [Self].
  14. var TODO Actor = unrestricted{}
  15. // unrestricted is an [Actor] that has unlimited access to the currently running
  16. // tailscaled instance. It's typically used for operations performed by tailscaled
  17. // on its own, or upon a request from the control plane, rather on behalf of a user.
  18. type unrestricted struct{}
  19. // UserID implements [Actor].
  20. func (unrestricted) UserID() ipn.WindowsUserID { return "" }
  21. // Username implements [Actor].
  22. func (unrestricted) Username() (string, error) { return "", nil }
  23. // Context implements [Actor].
  24. func (unrestricted) Context() context.Context { return context.Background() }
  25. // ClientID implements [Actor].
  26. // It always returns (NoClientID, false) because the tailscaled itself
  27. // is not a connected LocalAPI client.
  28. func (unrestricted) ClientID() (_ ClientID, ok bool) { return NoClientID, false }
  29. // CheckProfileAccess implements [Actor].
  30. func (unrestricted) CheckProfileAccess(_ ipn.LoginProfileView, _ ProfileAccess, _ AuditLogFunc) error {
  31. // Unrestricted access to all profiles.
  32. return nil
  33. }
  34. // IsLocalSystem implements [Actor].
  35. //
  36. // Deprecated: this method exists for compatibility with the current (as of 2025-01-28)
  37. // permission model and will be removed as we progress on tailscale/corp#18342.
  38. func (unrestricted) IsLocalSystem() bool { return false }
  39. // IsLocalAdmin implements [Actor].
  40. //
  41. // Deprecated: this method exists for compatibility with the current (as of 2025-01-28)
  42. // permission model and will be removed as we progress on tailscale/corp#18342.
  43. func (unrestricted) IsLocalAdmin(operatorUID string) bool { return false }
  44. // IsTailscaled reports whether the given Actor represents Tailscaled itself,
  45. // such as [Self] or a [TODO] placeholder actor.
  46. func IsTailscaled(a Actor) bool {
  47. _, ok := a.(unrestricted)
  48. return ok
  49. }