Skip to content

Commit

Permalink
fix: makes file-based ACL accessible from APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Mar 7, 2024
1 parent d0b500b commit a80992d
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions hscontrol/grpcv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,12 +659,31 @@ func (api headscaleV1APIServer) GetACL(
_ context.Context,
_ *v1.GetACLRequest,
) (*v1.GetACLResponse, error) {
acl, err := api.h.db.GetACL()
if err != nil {
if db.IsNotFoundError(err) {
return nil, types.ErrACLPolicyNotFound
var (
acl *types.ACL
err error
)

// Get the ACL from the database or the file, depending on the
// configuration. If the ACL is not found, return an error.
switch api.h.cfg.ACL.PolicyMode {
case types.ACLPolicyModeDB:
acl, err = api.h.db.GetACL()
if err != nil {
if db.IsNotFoundError(err) {
return nil, types.ErrACLPolicyNotFound
}
return nil, err
}
case types.ACLPolicyModeFile:
aclBytes, err := api.h.ACLPolicy.Bytes()
if err != nil {
return nil, err
}

acl = &types.ACL{
Policy: aclBytes,
}
return nil, err
}

return &v1.GetACLResponse{
Expand Down

0 comments on commit a80992d

Please sign in to comment.