Files
Lucas Manuel Rodriguez 590bf185c2 Fix missing tags for OPA policy (#46203)
Resolves #46009.

- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.

## Testing

- [X] Added/updated automated tests
- [X] QA'd all new/changed functionality manually

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Fixed permissions for host activity items by aligning serialized field
names used by authorization rules, ensuring fleet-scoped users receive
correct access rights when listing and reading host activities.

* **Tests**
* Added authorization tests validating host activity access control
across user roles and team scopes, including denial cases for
unauthorized and GitOps-scoped users, and verifying policy evaluation
depends on correct serialized field naming.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/fleetdm/fleet/pull/46203?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-26 15:15:38 -03:00

25 lines
913 B
Go

package activity
import "context"
// Host represents minimal host info needed by the activity context for authorization.
// The json tags must match the field names referenced by the OPA policy (see
// server/authz/policy.rego), otherwise authorization checks that depend on
// object.team_id (e.g. team-scoped admins reading host activities) will fail.
type Host struct {
ID uint `json:"id"`
TeamID *uint `json:"team_id"` //nolint apiparamcheck // internal struct, tag used by OPA policy engine, not emitted to user
}
// AuthzType returns the authorization type for hosts.
func (h *Host) AuthzType() string {
return "host"
}
// HostProvider is the interface for fetching host data.
type HostProvider interface {
// GetHostLite returns minimal host information for authorization.
// If the host doesn't exist, returns a NotFoundError.
GetHostLite(ctx context.Context, hostID uint) (*Host, error)
}