Skip to content

Commit 1d545ed

Browse files
committed
WIP - PR(AAC) messy implementation
1 parent 8dc372a commit 1d545ed

46 files changed

Lines changed: 2928 additions & 65 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

acp/types/types.go

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
package acp_types
1212

13-
import "github.com/sourcenetwork/acp_core/pkg/types"
13+
import (
14+
"strings"
15+
16+
"github.com/sourcenetwork/acp_core/pkg/types"
17+
)
1418

1519
// RequiredRegistererRelationName is the required relation name that any registerer will have,
1620
// as the registerer is guaranteed to be the owner.
@@ -74,9 +78,14 @@ const (
7478
AdminDACEnablePerm
7579
AdminDACDisablePerm
7680
AdminDACPurgePerm
77-
AdminAACEnablePerm
81+
AdminDACStatusPerm
82+
AdminDACRelationAddPerm
83+
AdminDACRelationDeletePerm
84+
AdminDACPolicyAddPerm
85+
AdminAACReEnablePerm
7886
AdminAACDisablePerm
7987
AdminAACPurgePerm
88+
AdminAACStatusPerm
8089
AdminAACRelationAddPerm
8190
AdminAACRelationDeletePerm
8291
)
@@ -89,9 +98,14 @@ var RequiredResourcePermissionsForAdmin = []string{
8998
"dac-enable",
9099
"dac-disable",
91100
"dac-purge",
92-
"aac-enable",
101+
"dac-status",
102+
"dac-relation-add",
103+
"dac-relation-delete",
104+
"dac-policy-add",
105+
"aac-re-enable",
93106
"aac-disable",
94107
"aac-purge",
108+
"aac-status",
95109
"aac-relation-add",
96110
"aac-relation-delete",
97111
}
@@ -111,29 +125,39 @@ resources:
111125
node:
112126
permissions:
113127
dac-bypass:
114-
expr: owner + super-admin
128+
expr: owner + admin
115129
dac-enable:
116-
expr: owner + super-admin
130+
expr: owner + admin
117131
dac-disable:
118-
expr: owner + super-admin
132+
expr: owner + admin
119133
dac-purge:
120-
expr: owner + super-admin
121-
aac-enable:
122-
expr: owner + super-admin
134+
expr: owner + admin
135+
dac-status:
136+
expr: owner + admin
137+
dac-relation-add:
138+
expr: owner + admin
139+
dac-relation-delete:
140+
expr: owner + admin
141+
dac-policy-add:
142+
expr: owner + admin
143+
aac-re-enable:
144+
expr: owner + admin
123145
aac-disable:
124-
expr: owner + super-admin
146+
expr: owner + admin
125147
aac-purge:
126-
expr: owner + super-admin
148+
expr: owner + admin
149+
aac-status:
150+
expr: owner + admin
127151
aac-relation-add:
128-
expr: owner + super-admin
152+
expr: owner + admin
129153
aac-relation-delete:
130-
expr: owner + super-admin
154+
expr: owner + admin
131155
132156
relations:
133157
owner:
134158
types:
135159
- actor
136-
super-admin:
160+
admin:
137161
types:
138162
- actor
139163
`
@@ -142,6 +166,14 @@ func (resourcePermission AdminResourcePermission) String() string {
142166
return RequiredResourcePermissionsForAdmin[resourcePermission]
143167
}
144168

169+
func (resourcePermission AdminResourcePermission) IsForAACOperation() bool {
170+
permission := resourcePermission.String()
171+
if len(permission) >= 3 && strings.EqualFold(permission[:3], "aac") {
172+
return true
173+
}
174+
return false
175+
}
176+
145177
// RegistrationResult is an enum type which indicates the result of a RegisterObject call to SourceHub / ACP Core
146178
type RegistrationResult int32
147179

cli/acp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
func MakeACPCommand() *cobra.Command {
1818
var cmd = &cobra.Command{
1919
Use: "acp",
20-
Short: "Interact with the access control system of a DefraDB node",
21-
Long: `Interact with the access control system of a DefraDB node
20+
Short: "Interact with the access control system(s) of a DefraDB node",
21+
Long: `Interact with the access control system(s) of a DefraDB node
2222
2323
Learn more about the DefraDB [ACP System](/acp/README.md)
2424

cli/acp_aac.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2025 Democratized Data Foundation
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the file licenses/BSL.txt.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0, included in the file
9+
// licenses/APL.txt.
10+
11+
package cli
12+
13+
import (
14+
"github.com/spf13/cobra"
15+
)
16+
17+
func MakeAdminACPCommand() *cobra.Command {
18+
var cmd = &cobra.Command{
19+
Use: "aac",
20+
Short: "Interact with the admin access control system of a DefraDB node",
21+
Long: `Interact with the admin access control system of a DefraDB node
22+
Note:
23+
- Clean state means, if the access control was never configured, or the entire state was purged.
24+
- The check the admin acp status use the 'client acp aac status' command
25+
- To re-enable temporarily disabled admin acp, use the 'client acp aac re-enable' command.
26+
- To temporarily disabled admin acp, use the 'client acp aac disable' command.
27+
- To start admin acp for the first time, use the start command with '--acp-enable true'.
28+
- Specifying an identity is a MUST, when starting first time (from a clean state).
29+
- To give admin access to other users use the 'client acp aac relationship add' command.
30+
- To revoke admin access from other users use the 'client acp aac relationship delete' command.
31+
- To reset/purge acp state into a clean state, use the 'client acp aac purge' command.
32+
- Purge command(s) require the user to be in dev-mode (Warning: all state will be lost).
33+
34+
Learn more about the DefraDB [ACP System](/acp/README.md)
35+
36+
`,
37+
}
38+
39+
return cmd
40+
}

cli/acp_aac_disable.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2025 Democratized Data Foundation
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the file licenses/BSL.txt.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0, included in the file
9+
// licenses/APL.txt.
10+
11+
package cli
12+
13+
import (
14+
"github.com/spf13/cobra"
15+
16+
"github.com/sourcenetwork/defradb/client"
17+
)
18+
19+
func MakeAdminACPDisableCommand() *cobra.Command {
20+
var cmd = &cobra.Command{
21+
Use: "disable [-i --identity]",
22+
Short: "Disable the admin access control",
23+
Long: `Disable the admin access control
24+
25+
Example:
26+
defradb client acp aac disable -i 028d53f37a19afb9a0dbc5b4be30c65731479ee8cfa0c9bc8f8bf198cc3c075f
27+
28+
Note:
29+
- This command will disable an admin acp system that is currently enabled.
30+
- If admin acp is already disabled, then it will return an error.
31+
- If admin acp is in a clean/non-configured state, then it will return an error.
32+
33+
For quick help: 'defradb client acp aac --help'
34+
35+
Learn more about the DefraDB [ACP System](/acp/README.md)
36+
37+
`,
38+
RunE: func(cmd *cobra.Command, args []string) error {
39+
db := mustGetContextDB(cmd)
40+
if err := db.DisableAdminACP(cmd.Context()); err != nil {
41+
return err
42+
}
43+
44+
return writeJSON(cmd, client.SuccessResponse{Success: true})
45+
},
46+
}
47+
return cmd
48+
}

cli/acp_aac_re-enable.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2025 Democratized Data Foundation
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the file licenses/BSL.txt.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0, included in the file
9+
// licenses/APL.txt.
10+
11+
package cli
12+
13+
import (
14+
"github.com/spf13/cobra"
15+
16+
"github.com/sourcenetwork/defradb/client"
17+
)
18+
19+
func MakeAdminACPReEnableCommand() *cobra.Command {
20+
var cmd = &cobra.Command{
21+
Use: "re-enable [-i --identity]",
22+
Short: "Re-enable the admin access control",
23+
Long: `Re-enable the admin access control
24+
25+
Example:
26+
defradb client acp aac re-enable -i 028d53f37a19afb9a0dbc5b4be30c65731479ee8cfa0c9bc8f8bf198cc3c075f
27+
28+
Note:
29+
- This command will re-enable an already configured admin acp system that is temporarily disabled.
30+
- If admin acp is already enabled, then it will return an error.
31+
- If admin acp is in a clean/non-configured state, then it will return an error.
32+
33+
For quick help: 'defradb client acp aac --help'
34+
35+
Learn more about the DefraDB [ACP System](/acp/README.md)
36+
37+
`,
38+
RunE: func(cmd *cobra.Command, args []string) error {
39+
db := mustGetContextDB(cmd)
40+
if err := db.ReEnableAdminACP(cmd.Context()); err != nil {
41+
return err
42+
}
43+
44+
return writeJSON(cmd, client.SuccessResponse{Success: true})
45+
},
46+
}
47+
return cmd
48+
}

cli/acp_aac_status.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2025 Democratized Data Foundation
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the file licenses/BSL.txt.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0, included in the file
9+
// licenses/APL.txt.
10+
11+
package cli
12+
13+
import (
14+
"github.com/spf13/cobra"
15+
)
16+
17+
func MakeAdminACPStatusCommand() *cobra.Command {
18+
var cmd = &cobra.Command{
19+
Use: "status [-i --identity]",
20+
Short: "Check the admin access control status",
21+
Long: `Check the admin access control status
22+
23+
Example:
24+
defradb client acp aac status -i 028d53f37a19afb9a0dbc5b4be30c65731479ee8cfa0c9bc8f8bf198cc3c075f
25+
26+
Note:
27+
- If Admin ACP is in clean state (not configured) the status has [IsConfigured] == false.
28+
- If Admin ACP is temporarily disabled, then [IsConfigured] == true and [IsEnabled] == false.
29+
- If Admin ACP is enabled then [IsEnabled] == true.
30+
31+
For quick help: 'defradb client acp aac --help'
32+
33+
Learn more about the DefraDB [ACP System](/acp/README.md)
34+
35+
`,
36+
RunE: func(cmd *cobra.Command, args []string) error {
37+
db := mustGetContextDB(cmd)
38+
status, err := db.AdminACPStatus(cmd.Context())
39+
if err != nil {
40+
return err
41+
}
42+
return writeJSON(cmd, status)
43+
},
44+
}
45+
return cmd
46+
}

cli/cli.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ func NewDefraCommand() *cobra.Command {
6161
MakeSchemaDescribeCommand(),
6262
)
6363

64+
aac := MakeAdminACPCommand()
65+
aac.AddCommand(
66+
MakeAdminACPReEnableCommand(),
67+
MakeAdminACPDisableCommand(),
68+
MakeAdminACPStatusCommand(),
69+
)
70+
6471
acp_dac_policy := MakeDocumentACPPolicyCommand()
6572
acp_dac_policy.AddCommand(
6673
MakeDocumentACPPolicyAddCommand(),
@@ -80,6 +87,7 @@ func NewDefraCommand() *cobra.Command {
8087

8188
acp := MakeACPCommand()
8289
acp.AddCommand(
90+
aac,
8391
dac,
8492
)
8593

cli/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var configFlags = map[string]string{
6767
"keyring-backend": "keyring.backend",
6868
"keyring-path": "keyring.path",
6969
"no-keyring": "keyring.disabled",
70+
"aac-enable": "acp.aac.enable",
7071
"dac-type": "acp.dac.type",
7172
"source-hub-address": "acp.dac.sourceHub.address",
7273
"development": "development",
@@ -104,6 +105,7 @@ var configDefaults = map[string]any{
104105
"telemetry.disabled": false,
105106
"datastore.nosigning": false,
106107
"datastore.defaultkeytype": "secp256k1",
108+
"acp.aac.enable": false,
107109
"acp.dac.type": "none",
108110
"replicator.retryintervals": []int{30, 60, 120, 240, 480, 960, 1920},
109111
}

cli/server_dump.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ func MakeServerDumpCmd() *cobra.Command {
3737
if err != nil {
3838
return err
3939
}
40-
db, err := db.NewDB(cmd.Context(), rootstore, dac.NoDocumentACP, nil)
40+
db, err := db.NewDB(
41+
cmd.Context(),
42+
rootstore,
43+
db.NewCleanAdminInfo(),
44+
dac.NoDocumentACP,
45+
nil,
46+
)
4147
if err != nil {
4248
return errors.Wrap("failed to initialize database", err)
4349
}

0 commit comments

Comments
 (0)