Skip to content

Commit

Permalink
Merge pull request #13 from enclaive/backend-did-build
Browse files Browse the repository at this point in the history
Backend did build
  • Loading branch information
marcely0 authored May 8, 2023
2 parents 756f4a5 + 60d6cc7 commit 11dbaa8
Show file tree
Hide file tree
Showing 57 changed files with 2,666 additions and 558 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
!build
!metadata.json
!docker-extension/build
!confidential-templates.json
3 changes: 2 additions & 1 deletion .vscode.example/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"go.lintTool": "golangci-lint",
"go.lintFlags": ["--fast", "-E", "exportloopref"],
"gopls": {
"build.expandWorkspaceToModule": false
"build.expandWorkspaceToModule": false,
"importShortcut": "Definition"
},
"gitlens.advanced.blame.customArguments": ["--ignore-revs-file", ".git-blame-ignore-revs"]
}
21 changes: 21 additions & 0 deletions Dockerfile.graminehello
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install curl gnupg git -y
RUN curl -fsSLo /usr/share/keyrings/gramine-keyring.gpg https://packages.gramineproject.io/gramine-keyring.gpg
RUN echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/gramine-keyring.gpg] https://packages.gramineproject.io/ focal main' | tee /etc/apt/sources.list.d/gramine.list
RUN curl -fsSL https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add -
RUN echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | tee /etc/apt/sources.list.d/intel-sgx.list
RUN apt-get update
RUN apt-get install gramine -y

RUN gramine-sgx-gen-private-key

RUN git clone --depth 1 --branch v1.3.1 https://github.com/gramineproject/gramine.git

RUN apt-get install gcc make -y

WORKDIR gramine/CI-Examples/helloworld

RUN ls

RUN make SGX=1
2 changes: 2 additions & 0 deletions Dockerfile.marialable
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM sgxdcaprastuff/gramine-mariadb
LABEL pcc.mrenclave=e556b1f4a686be466b24c8d13df07705d5c1b9c8441281b84aec16c3d778521b pcc.mrsigner=idkidkidk
2 changes: 2 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM scratch
LABEL pcc.mrenclave=TEST2 pcc.mrsigner=test2
40 changes: 40 additions & 0 deletions api/confidential-templates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"ImageName": "sgxdcaprastuff/gramine-mariadb",
"LogoURL": "https://mariadb.com/wp-content/uploads/2019/11/mariadb-logo-vert_blue-transparent.png",
"TemplateName": "mariatemplate",
"Inputs": [
"username",
"password"
],
"Secrets": {
"init": "CREATE OR REPLACE USER $$$username$$$ IDENTIFIED BY '$$$password$$$';\n GRANT ALL PRIVILEGES ON *.* TO $$$username$$$ ;"
},
"ManifestBoilerplate": {
"ManifestParameters": {
"Files": {
"/app/init.sql": {
"Data": "{{ raw .Secrets.init.Private }}",
"Encoding": "string",
"NoTemplates": false
},
"/dev/attestation/keys/default": {
"Data": "{{ raw .Secrets.app_defaultkey.Private }}",
"Encoding": "string",
"NoTemplates": false
}
},
"Argv": [
"/app/mariadbd",
"--init-file=/app/init.sql"
]
},
"ManifestSecrets": {
"init": {
"type": "plain",
"UserDefined": true
}
}
}
}
]
77 changes: 77 additions & 0 deletions api/dataservices/confidentialtemplate/confidentialtemplate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package confidentialtemplate

import (
"fmt"

"github.com/rs/zerolog/log"

portainer "github.com/portainer/portainer/api"
)

const (
BucketName = "confidentialtemplates"
)

type Service struct {
connection portainer.Connection
}

func (service *Service) BucketName() string {
return BucketName
}

// NewService creates a new instance of this conf. compute service.
func NewService(connection portainer.Connection) (*Service, error) {
err := connection.SetServiceName(BucketName)
if err != nil {
return nil, err
}

return &Service{
connection: connection,
}, nil
}

func (service *Service) Create(conftemplateObject *portainer.ConfidentialTemplate) error {

return service.connection.CreateObject(
BucketName,
func(id uint64) (int, interface{}) {
conftemplateObject.ID = portainer.ConfidentialTemplateId(id)
return int(id), conftemplateObject
},
)
}

func (service *Service) ConfidentialTemplate(ID portainer.ConfidentialTemplateId) (*portainer.ConfidentialTemplate, error) {
var template portainer.ConfidentialTemplate
identifier := service.connection.ConvertToKey(int(ID))

err := service.connection.GetObject(BucketName, identifier, &template)
if err != nil {
return nil, err
}

return &template, nil
}

func (service *Service) ConfidentialTemplates() ([]portainer.ConfidentialTemplate, error) {
var templates = make([]portainer.ConfidentialTemplate, 0)

err := service.connection.GetAll(
BucketName,
&portainer.ConfidentialTemplate{},
func(obj interface{}) (interface{}, error) {
template, ok := obj.(*portainer.ConfidentialTemplate)
if !ok {
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to confidential image object")
return nil, fmt.Errorf("Failed to convert to confidential image object: %s", obj)
}

templates = append(templates, *template)

return &portainer.ConfidentialTemplate{}, nil
})

return templates, err
}
8 changes: 8 additions & 0 deletions api/dataservices/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type (
Webhook() WebhookService
Key() KeyService
SecureImage() SecureImageService
ConfidentialTemplate() ConfidentialTemplateService
}

// CoordinatorService for managing coordinators
Expand Down Expand Up @@ -355,6 +356,13 @@ type (
SecureImages() ([]portainer.SecureImage, error)
BucketName() string
}

ConfidentialTemplateService interface {
ConfidentialTemplate(ID portainer.ConfidentialTemplateId) (*portainer.ConfidentialTemplate, error)
ConfidentialTemplates() ([]portainer.ConfidentialTemplate, error)
Create(conftemplateObject *portainer.ConfidentialTemplate) error
BucketName() string
}
)

func IsErrObjectNotFound(e error) bool {
Expand Down
12 changes: 12 additions & 0 deletions api/datastore/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/dataservices"
"github.com/portainer/portainer/api/dataservices/apikeyrepository"
"github.com/portainer/portainer/api/dataservices/confidentialtemplate"
"github.com/portainer/portainer/api/dataservices/coordinator"
coordoinatordeployment "github.com/portainer/portainer/api/dataservices/coordinatordeployment"
"github.com/portainer/portainer/api/dataservices/customtemplate"
Expand Down Expand Up @@ -82,6 +83,7 @@ type Store struct {
WebhookService *webhook.Service
KeyService *key.Service
SecureImageService *secureimage.Service
ConfidentialTemplateService *confidentialtemplate.Service
}

func (store *Store) initServices() error {
Expand Down Expand Up @@ -277,6 +279,12 @@ func (store *Store) initServices() error {
}
store.SecureImageService = secureImageService

confidentialTemplateService, err := confidentialtemplate.NewService(store.connection)
if err != nil {
return err
}
store.ConfidentialTemplateService = confidentialTemplateService

return nil
}

Expand Down Expand Up @@ -421,6 +429,10 @@ func (store *Store) SecureImage() dataservices.SecureImageService {
return store.SecureImageService
}

func (store *Store) ConfidentialTemplate() dataservices.ConfidentialTemplateService {
return store.ConfidentialTemplateService
}

type storeExport struct {
CustomTemplate []portainer.CustomTemplate `json:"customtemplates,omitempty"`
EdgeGroup []portainer.EdgeGroup `json:"edgegroups,omitempty"`
Expand Down
51 changes: 51 additions & 0 deletions api/http/handler/portainercc/confidential_templates_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package portainercc

import (
"encoding/json"
"net/http"

httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/response"
portainer "github.com/portainer/portainer/api"
)

type ConfTempParams struct {
ImageName string
LogoURL string
TemplateName string
Inputs []portainer.Input
Secrets map[string]string
ManifestBoilerplate struct {
ManifestParameters portainer.Parameters
ManifestSecrets map[string]portainer.Secret
}
}

func (handler *Handler) createConfidentialTemplate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
var params ConfTempParams
err := json.NewDecoder(r.Body).Decode(&params)

if err != nil {
return httperror.BadRequest("request body malefomred", err)
}

templateObject := &portainer.ConfidentialTemplate{
ImageName: params.ImageName,
LogoURL: params.LogoURL,
TemplateName: params.TemplateName,
Inputs: params.Inputs,
Secrets: params.Secrets,
ManifestBoilerplate: struct {
ManifestParameters portainer.Parameters "json:\"ManifestParameters\""
ManifestSecrets map[string]portainer.Secret "json:\"ManifestSecrets\""
}(params.ManifestBoilerplate),
}

err = handler.DataStore.ConfidentialTemplate().Create(templateObject)

if err != nil {
return httperror.InternalServerError("could not save template in db", err)
}

return response.JSON(w, templateObject)
}
Loading

0 comments on commit 11dbaa8

Please sign in to comment.