Skip to content

Commit

Permalink
marble: log TTLS config
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasten authored and daniel-weisse committed Feb 27, 2024
1 parent 0330ced commit 227ba93
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/docs/workflows/define-manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,10 @@ Incoming connections are defined by `Port`. For services used by external client
}
}
```
:::tip
On startup, a Marble logs its effective TTLS policy.
This helps to verify that the manifest configuration is applied as intended.
:::
39 changes: 39 additions & 0 deletions marble/premain/premain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"context"
"crypto/ecdsa"
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -191,6 +192,9 @@ func PreMainEx(issuer quote.Issuer, activate ActivateFunc, hostfs, enclavefs afe
return err
}

if err := logTTLS(params.Env); err != nil {
return err
}
if err := applyParameters(params, enclavefs); err != nil {
return err
}
Expand Down Expand Up @@ -231,6 +235,41 @@ func activateRPC(req *rpc.ActivationReq, coordAddr string, tlsCredentials creden
return activationResp.GetParameters(), nil
}

func logTTLS(env map[string][]byte) error {
ttlsConfigJSON, ok := env[constants.EnvMarbleTTLSConfig]
if !ok {
log.Println("Not using TTLS")
return nil
}

var ttlsConfig map[string]map[string]map[string]map[string]interface{}
if err := json.Unmarshal(ttlsConfigJSON, &ttlsConfig); err != nil {
return fmt.Errorf("unmarshaling TTLS config: %w", err)
}
tls := ttlsConfig["tls"]
incoming := tls["Incoming"]
outgoing := tls["Outgoing"]
if len(incoming) == 0 && len(outgoing) == 0 {
return errors.New("TTLS config is empty")
}

log.Println("TTLS config")
if len(incoming) > 0 {
log.Println(" Incoming")
for k := range incoming {
log.Print(" ", k)
}
}
if len(outgoing) > 0 {
log.Println(" Outgoing")
for k := range outgoing {
log.Print(" ", k)
}
}

return nil
}

func applyParameters(params *rpc.Parameters, fs afero.Fs) error {
// Store files in file system
log.Println("creating files from manifest")
Expand Down
17 changes: 17 additions & 0 deletions marble/premain/premain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/edgelesssys/marblerun/coordinator/quote"
"github.com/edgelesssys/marblerun/coordinator/rpc"
"github.com/edgelesssys/marblerun/internal/constants"
"github.com/edgelesssys/marblerun/marble/config"
"github.com/google/uuid"
"github.com/spf13/afero"
Expand Down Expand Up @@ -143,6 +144,22 @@ func TestPreMain(t *testing.T) {
assert.Equal("", os.Getenv("EDG_TEST_1"))
assert.Equal("", os.Getenv("EDG_TEST_2"))

assert.Equal([]string{"not modified"}, os.Args)
}
{ // fail on empty TTLS config
parameters = &rpc.Parameters{
Env: map[string][]byte{
constants.EnvMarbleTTLSConfig: []byte(`{"tls":{}}`),
},
}
activateError = nil

os.Args = []string{"not modified"}

hostfs := afero.NewMemMapFs()
enclavefs := afero.NewMemMapFs()
require.Error(PreMainEx(issuer, activate, hostfs, enclavefs))

assert.Equal([]string{"not modified"}, os.Args)
}
}

0 comments on commit 227ba93

Please sign in to comment.