Skip to content

Commit e2c47b8

Browse files
committed
feat(cmd/rofl): Add support for machine permissions
1 parent 29d5a9b commit e2c47b8

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

build/rofl/manifest.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ type Machine struct {
408408
Offer string `yaml:"offer,omitempty" json:"offer,omitempty"`
409409
// ID is the identifier of the machine to deploy into.
410410
ID string `yaml:"id,omitempty" json:"id,omitempty"`
411+
412+
// Permissions is a map of permissions for the machine.
413+
Permissions map[string][]string `yaml:"permissions,omitempty" json:"permissions,omitempty"`
411414
}
412415

413416
// Validate validates the machine for correctness.

build/rofl/scheduler/metadata.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ const (
1111
MetadataKeySchedulerAPI = "net.oasis.scheduler.api"
1212
// MetadataKeyProxyDomain is the name of the metadata key that stores the proxy domain.
1313
MetadataKeyProxyDomain = "net.oasis.proxy.domain"
14+
// MetadataKeyPermissions is the name of the deployment metadata key that stores the machine
15+
// permissions.
16+
MetadataKeyPermissions = "net.oasis.scheduler.permissions"
17+
// MetadataKeyORCReference is the name of the deployment metadata key that stores the ORC
18+
// reference.
19+
MetadataKeyORCReference = "net.oasis.deployment.orc.ref"
1420
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package scheduler
2+
3+
import (
4+
"encoding/base64"
5+
6+
"github.com/oasisprotocol/oasis-core/go/common/cbor"
7+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
8+
)
9+
10+
const (
11+
// MachinePermissionLogView is the permission required to view logs.
12+
MachinePermissionLogView = "log.view"
13+
)
14+
15+
// Permissions is a map of actions to addresses that are allowed to perform them.
16+
type Permissions map[string][]types.Address
17+
18+
// MarshalPermissions marshals the permissions map into a base64-encoded CBOR string.
19+
func MarshalPermissions(permissions Permissions) string {
20+
encPerms := cbor.Marshal(permissions)
21+
return base64.StdEncoding.EncodeToString(encPerms)
22+
}

cmd/rofl/deploy.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,16 @@ var (
144144
AppID: appID,
145145
ManifestHash: manifestHash,
146146
Metadata: map[string]string{
147-
"net.oasis.deployment.orc.ref": fmt.Sprintf("%s@%s", deployment.OCIRepository, ociDigest),
147+
scheduler.MetadataKeyORCReference: fmt.Sprintf("%s@%s", deployment.OCIRepository, ociDigest),
148148
},
149149
}
150+
if len(machine.Permissions) > 0 {
151+
perms, err := resolveAndMarshalPermissions(npa, machine.Permissions)
152+
if err != nil {
153+
cobra.CheckErr(fmt.Sprintf("Failed to marshal permissions: %s", err))
154+
}
155+
machineDeployment.Metadata[scheduler.MetadataKeyPermissions] = perms
156+
}
150157

151158
obtainMachine := func() (*buildRofl.Machine, *roflmarket.Instance, error) {
152159
if deployOffer != "" {
@@ -446,6 +453,22 @@ func term2str(term roflmarket.Term) string {
446453
}
447454
}
448455

456+
func resolveAndMarshalPermissions(npa *common.NPASelection, permissions map[string][]string) (string, error) {
457+
perms := make(scheduler.Permissions)
458+
for action, addresses := range permissions {
459+
perms[action] = make([]types.Address, len(addresses))
460+
for i, rawAddr := range addresses {
461+
addr, _, err := common.ResolveLocalAccountOrAddress(npa.Network, rawAddr)
462+
if err != nil {
463+
return "", err
464+
}
465+
466+
perms[action][i] = *addr
467+
}
468+
}
469+
return scheduler.MarshalPermissions(perms), nil
470+
}
471+
449472
func init() {
450473
providerFlags := flag.NewFlagSet("", flag.ContinueOnError)
451474
// Default to Testnet playground provider.

cmd/rofl/machine/logs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ var logsCmd = &cobra.Command{
8989
func init() {
9090
logsCmd.Flags().AddFlagSet(roflCommon.DeploymentFlags)
9191
logsCmd.Flags().AddFlagSet(common.AnswerYesFlag)
92+
logsCmd.Flags().AddFlagSet(common.AccountFlag)
9293
}

0 commit comments

Comments
 (0)