Skip to content

Commit

Permalink
extract uniqueid and signerid
Browse files Browse the repository at this point in the history
  • Loading branch information
thilovoss committed Oct 24, 2022
1 parent 1d33225 commit 69cb4c6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9
github.com/docker/cli v20.10.9+incompatible
github.com/docker/docker v20.10.16+incompatible
github.com/docker/go-connections v0.4.0
github.com/fvbommel/sortorder v1.0.2
github.com/fxamacker/cbor/v2 v2.3.0
github.com/g07cha/defender v0.0.0-20180505193036-5665c627c814
Expand Down Expand Up @@ -69,7 +70,6 @@ require (
github.com/containerd/containerd v1.6.8 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.0+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
Expand Down
2 changes: 0 additions & 2 deletions api/http/handler/endpointproxy/proxy_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import (
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"
portainer "github.com/portainer/portainer/api"
"github.com/rs/zerolog/log"
)

func (handler *Handler) proxyRequestsToDockerAPI(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
log.Info().Msg("creating proxy")
endpointID, err := request.RetrieveNumericRouteVariableValue(r, "id")
if err != nil {
return httperror.BadRequest("Invalid environment identifier route variable", err)
Expand Down
47 changes: 38 additions & 9 deletions api/http/handler/ra/ra_coordinator_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -87,7 +88,10 @@ func (handler *Handler) raCoordinatorBuild(w http.ResponseWriter, r *http.Reques
Dockerfile: "./dockerfile/Dockerfile.coordinator",
Tags: []string{"coordinator/" + params.Name},
BuildArgs: map[string]*string{"signingkey": &signingKey},
Outputs: []types.ImageBuildOutput{},
Outputs: []types.ImageBuildOutput{
{Type: "local"},
},
NoCache: true,
}

// send image build request
Expand All @@ -96,22 +100,47 @@ func (handler *Handler) raCoordinatorBuild(w http.ResponseWriter, r *http.Reques
return httperror.InternalServerError("Unable to build Coordinator image", err)
}
defer res.Body.Close()
err = print(res.Body)

coordinatorObject := &portainer.Coordinator{
Name: params.Name,
SigningKeyID: params.SigningKeyId,
}

// extract UniqueID and SignerID from Build Logs
scanner := bufio.NewScanner(res.Body)
var lastLine string
for scanner.Scan() {
lastLine = scanner.Text()
if strings.Contains(lastLine, "UniqueID") {
split := strings.Split(lastLine, ",")
for _, line := range split {
fmt.Println(line)
if strings.Contains(line, "UniqueID") {
uniqueID := strings.Split(line, ":")[1]
uniqueID = strings.ReplaceAll(uniqueID, `\"`, "")
uniqueID = strings.ReplaceAll(uniqueID, ` `, "")
coordinatorObject.UniqueID = uniqueID
}
if strings.Contains(line, "SignerID") {
signerID := strings.Split(line, ":")[1]
signerID = strings.ReplaceAll(signerID, `\"`, "")
signerID = strings.ReplaceAll(signerID, ` `, "")
coordinatorObject.SignerID = signerID
}
}
}
}
fmt.Println(coordinatorObject.SignerID)
fmt.Println(coordinatorObject.UniqueID)

// get image id of built image
imgMeta, _, err := client.ImageInspectWithRaw(r.Context(), "coordinator/"+params.Name)
if err != nil {
return httperror.InternalServerError("Unable to retrieve new coordinators image id", err)
}

// TODO extract MRENCLAVE and MRSIGNER
coordinatorObject.ImageID = strings.Split(imgMeta.ID, ":")[1]

// create new coordinator in database
coordinatorObject := &portainer.Coordinator{
Name: params.Name,
SigningKeyID: params.SigningKeyId,
ImageID: strings.Split(imgMeta.ID, ":")[1],
}
err = handler.DataStore.Coordinator().Create(coordinatorObject)
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to generate new coordinator", err}
Expand Down
2 changes: 2 additions & 0 deletions api/portainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ type (
Name string `json:"name"`
ImageID string `json:"imageId"`
SigningKeyID int `json:"signingKeyId"`
UniqueID string `json:"uniqueId"`
SignerID string `json:"signerId"`
}

CoordinatorID int
Expand Down
3 changes: 2 additions & 1 deletion coordinator/dockerfile/Dockerfile.coordinator
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ WORKDIR /coordinator/build
RUN cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
# RUN --mount=type=secret,id=signingkey,dst=/coordinator/build/private.pem,required=true make sign-coordinator coordinator-noenclave
RUN echo "$signingkey" > /coordinator/build/private.pem
RUN cat /coordinator/build/private.pem

RUN make sign-coordinator coordinator-noenclave
#COPY ./build/private.pem /coordinator/build/private.pem
#RUN cat /coordinator/build/private.pem
RUN cat ./coordinator-config.json


FROM ghcr.io/edgelesssys/edgelessrt-deploy AS release
LABEL description="EdgelessCoordinator"
Expand Down
Empty file added yarn-error.log
Empty file.

0 comments on commit 69cb4c6

Please sign in to comment.