Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tavern/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ func NewServer(ctx context.Context, options ...func(*Config)) (*Server, error) {
AllowUnactivated: true,
},
"/auth/rda/approve": tavernhttp.Endpoint{
Handler: tavernhttp.NewRDAApproveHandler(client),
Handler: tavernhttp.NewRDAApproveHandler(client),
},
"/auth/rda/revoke": tavernhttp.Endpoint{
Handler: tavernhttp.NewRDARevokeHandler(client),
Handler: tavernhttp.NewRDARevokeHandler(client),
},
"/api/auth/signout": tavernhttp.Endpoint{
Handler: tavernhttp.NewSignoutHandler(),
Expand Down
2 changes: 0 additions & 2 deletions tavern/cli/auth/options.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package auth



type AuthOptions struct {
EnvAPIKeyName string
CachePath string
Expand Down
4 changes: 2 additions & 2 deletions tavern/internal/builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The builder package orchestrates agent compilation for target platforms. It conn

### future
- Add terraform for build server
- Register redirectors so bulider callback uri can be a drop down.
- Register redirectors so builder callback uri can be a drop down.
- Modifying the agent IMIX_CONFIG currently requires changes to both imix and tavern code bases now. Is there a way to codegen a YAML spec from tavern to the agent?
- De-dupe agent builds should the API stop builds that have the same params and point to the existing build? Or is this a UI thing?

Expand All @@ -33,7 +33,7 @@ The builder package orchestrates agent compilation for target platforms. It conn
- Target OS + Target Format ---> rust target
- TargetOS's only support certain formats
- where to get the realm source code from - pull public repo?
- Currentt pattern with arbitrary bulid script is RCE as a service. Scope and limit this to just build configuration options.
- Current pattern with arbitrary build script is RCE as a service. Scope and limit this to just build configuration options.
- upstream should be free form
- pubkey can be set by the server
## Overview
Expand Down
2 changes: 1 addition & 1 deletion tavern/internal/builder/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
// Keys ending in "-bin" use gRPC binary metadata encoding.
mdKeyBuilderCert = "builder-cert-bin"
mdKeyBuilderSignature = "builder-signature-bin"
mdKeyBuilderTimestamp = "builder-timestamp"
mdKeyBuilderTimestamp = "builder-timestamp"

// Maximum age for a timestamp to be considered valid.
maxTimestampAge = 5 * time.Minute
Expand Down
22 changes: 11 additions & 11 deletions tavern/internal/builder/build_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const (

// DefaultTransports is the default transport configuration for a build task.
var DefaultTransports = []builderpb.BuildProfileTransport{{
URI: "http://127.0.0.1:8000",
Interval: 5,
Type: c2pb.Transport_TRANSPORT_GRPC,
URI: "http://127.0.0.1:8000",
Interval: 5,
Type: c2pb.Transport_TRANSPORT_GRPC,
}}

// TargetFormat is an alias for builderpb.TargetFormat.
Expand All @@ -50,11 +50,11 @@ type buildKey struct {

// buildCommands maps (target_os, target_format) -> cargo build command.
var buildCommands = map[buildKey]string{
{c2pb.Host_PLATFORM_LINUX, builderpb.TargetFormat_TARGET_FORMAT_BIN}: "cargo build --release --bin imix --target=x86_64-unknown-linux-musl",
{c2pb.Host_PLATFORM_MACOS, builderpb.TargetFormat_TARGET_FORMAT_BIN}: "cargo zigbuild --release --target aarch64-apple-darwin",
{c2pb.Host_PLATFORM_WINDOWS, builderpb.TargetFormat_TARGET_FORMAT_BIN}: "cargo build --release --target=x86_64-pc-windows-gnu",
{c2pb.Host_PLATFORM_LINUX, builderpb.TargetFormat_TARGET_FORMAT_BIN}: "cargo build --release --bin imix --target=x86_64-unknown-linux-musl",
{c2pb.Host_PLATFORM_MACOS, builderpb.TargetFormat_TARGET_FORMAT_BIN}: "cargo zigbuild --release --target aarch64-apple-darwin",
{c2pb.Host_PLATFORM_WINDOWS, builderpb.TargetFormat_TARGET_FORMAT_BIN}: "cargo build --release --target=x86_64-pc-windows-gnu",
{c2pb.Host_PLATFORM_WINDOWS, builderpb.TargetFormat_TARGET_FORMAT_WINDOWS_SERVICE}: "cargo build --release --features win_service --target=x86_64-pc-windows-gnu",
{c2pb.Host_PLATFORM_WINDOWS, builderpb.TargetFormat_TARGET_FORMAT_CDYLIB}: "cargo build --release --lib --target=x86_64-pc-windows-gnu",
{c2pb.Host_PLATFORM_WINDOWS, builderpb.TargetFormat_TARGET_FORMAT_CDYLIB}: "cargo build --release --lib --target=x86_64-pc-windows-gnu",
}

// ValidateTargetFormat checks whether the given format is supported for the given OS.
Expand Down Expand Up @@ -101,10 +101,10 @@ func TransportTypeToString(t c2pb.Transport_Type) string {

// ImixTransportConfig represents the transport section of the IMIX configuration.
type ImixTransportConfig struct {
URI string `yaml:"URI"`
Interval int `yaml:"interval"`
Type string `yaml:"type"`
Extra string `yaml:"extra"`
URI string `yaml:"URI"`
Interval int `yaml:"interval"`
Type string `yaml:"type"`
Extra string `yaml:"extra"`
}

// ImixConfig represents the IMIX agent configuration YAML.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "realm.pub/tavern/internal/c2/c2pb"

// BuildProfileTransport represents a single transport configuration stored in the BuildTask entity.
type BuildProfileTransport struct {
URI string `json:"uri"`
Interval int `json:"interval"`
Type c2pb.Transport_Type `json:"type"`
Extra string `json:"extra,omitempty"`
URI string `json:"uri"`
Interval int `json:"interval"`
Type c2pb.Transport_Type `json:"type"`
Extra string `json:"extra,omitempty"`
}
18 changes: 9 additions & 9 deletions tavern/internal/builder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
maxConcurrentBuilds = 4

maxOutputChSize = 64
maxErrorChSize = 64
maxErrorChSize = 64
)

// builderCredentials implements grpc.PerRPCCredentials for mTLS authentication.
Expand Down Expand Up @@ -285,16 +285,16 @@ func executeTask(ctx context.Context, client builderpb.BuilderClient, exec execu
// Run the build through the executor.
// The executor closes both channels when done.
result, buildErr := exec.Build(ctx, executor.BuildSpec{
TaskID: task.Id,
TargetOS: task.TargetOs,
BuildImage: task.BuildImage,
BuildScript: task.BuildScript,
ArtifactPath: task.ArtifactPath,
Env: task.Env,
SetupScript: task.SetupScript,
TaskID: task.Id,
TargetOS: task.TargetOs,
BuildImage: task.BuildImage,
BuildScript: task.BuildScript,
ArtifactPath: task.ArtifactPath,
Env: task.Env,
SetupScript: task.SetupScript,
PreBuildScript: task.PreBuildScript,
PostBuildScript: task.PostBuildScript,
Tomes: tomes,
Tomes: tomes,
}, outputCh, errorCh)

// Wait for the collector goroutine to drain remaining channel data.
Expand Down
2 changes: 1 addition & 1 deletion tavern/internal/builder/executor/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func prepareMountDir(spec BuildSpec) (string, error) {
return tmpDir, fmt.Errorf("writing setup script: %w", err)
}
}

// Write pre-build script.
if spec.PreBuildScript != "" {
if err := os.WriteFile(filepath.Join(scriptsDir, "1_pre_build.sh"), []byte(spec.PreBuildScript), 0o755); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions tavern/internal/builder/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ func TestBuilderE2E(t *testing.T) {
SetBuildImage("golang:1.21").
SetDescription("An explicit profile").
SetTransports([]builderpb.BuildProfileTransport{{
URI: "https://callback.example.com",
Interval: 10,
Type: c2pb.Transport_TRANSPORT_GRPC,
URI: "https://callback.example.com",
Interval: 10,
Type: c2pb.Transport_TRANSPORT_GRPC,
}}).
SaveX(ctx)

Expand Down
2 changes: 1 addition & 1 deletion tavern/internal/builder/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *Server) ClaimBuildTasks(ctx context.Context, req *builderpb.ClaimBuildT

// Derive the IMIX config YAML from the build task's stored transports.
profile, err := claimedTask.Profile(ctx)
if err != nil || profile == nil{
if err != nil || profile == nil {
return nil, status.Errorf(codes.Internal, "failed to load build profile task %d: %v", taskID, err)
}
transports := profile.Transports
Expand Down
86 changes: 43 additions & 43 deletions tavern/internal/c2/api_fetch_asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package c2_test
import (
"bytes"
"context"
"crypto/rand"
"errors"
"fmt"
"io"
"testing"
"crypto/rand"

_ "github.com/mattn/go-sqlite3"
"github.com/stretchr/testify/assert"
Expand All @@ -16,14 +16,14 @@ import (
"google.golang.org/grpc/status"
"realm.pub/tavern/internal/c2/c2pb"
"realm.pub/tavern/internal/c2/c2test"
"realm.pub/tavern/internal/ent"
"realm.pub/tavern/internal/ent"
)

func TestFetchAsset(t *testing.T) {
// Setup Dependencies
client, graph, close, token := c2test.New(t)
defer close()
ctx := context.Background()
ctx := context.Background()

// Test Cases
type testCase struct {
Expand Down Expand Up @@ -59,31 +59,31 @@ func TestFetchAsset(t *testing.T) {

testHandler := func(t *testing.T, tc testCase) {
// Create Asset
var a *ent.Asset
if tc.fileSize > 0 {
// Generate Random Content
data := make([]byte, tc.fileSize)
_, err := rand.Read(data)
require.NoError(t, err)
var a *ent.Asset
if tc.fileSize > 0 {
// Generate Random Content
data := make([]byte, tc.fileSize)
_, err := rand.Read(data)
require.NoError(t, err)

a = graph.Asset.Create().
SetName(tc.fileName).
SetContent(data).
SaveX(ctx)
}
a = graph.Asset.Create().
SetName(tc.fileName).
SetContent(data).
SaveX(ctx)
}

// Ensure request contains JWT
if tc.req.Context == nil {
tc.req.Context = &c2pb.FetchAssetRequest_TaskContext{
TaskContext: &c2pb.TaskContext{Jwt: token},
}
} else {
switch c := tc.req.Context.(type) {
case *c2pb.FetchAssetRequest_TaskContext:
c.TaskContext.Jwt = token
case *c2pb.FetchAssetRequest_ShellTaskContext:
c.ShellTaskContext.Jwt = token
}
switch c := tc.req.Context.(type) {
case *c2pb.FetchAssetRequest_TaskContext:
c.TaskContext.Jwt = token
case *c2pb.FetchAssetRequest_ShellTaskContext:
c.ShellTaskContext.Jwt = token
}
}

// Send Request
Expand All @@ -99,36 +99,36 @@ func TestFetchAsset(t *testing.T) {
break
}

if err != nil {
st, ok := status.FromError(err)
require.True(t, ok)
// Check Status
require.Equal(t, tc.wantCode.String(), st.Code().String())
if st.Code() != codes.OK {
// Do not continue if we expected error code
return
}
}
if err != nil {
st, ok := status.FromError(err)
require.True(t, ok)
// Check Status
require.Equal(t, tc.wantCode.String(), st.Code().String())
if st.Code() != codes.OK {
// Do not continue if we expected error code
return
}
}

// Write Chunk
if resp != nil {
_, err = buf.Write(resp.Chunk)
require.NoError(t, err)
}
_, err = buf.Write(resp.Chunk)
require.NoError(t, err)
}
}

// Assert Content
if a != nil {
assert.Equal(t, a.Content, buf.Bytes())
if a != nil {
assert.Equal(t, a.Content, buf.Bytes())

// Assert Headers
metadata, err := stream.Header()
require.NoError(t, err)
require.Len(t, metadata.Get("sha3-256-checksum"), 1)
assert.Equal(t, a.Hash, metadata.Get("sha3-256-checksum")[0])
require.Len(t, metadata.Get("file-size"), 1)
assert.Equal(t, fmt.Sprintf("%d", a.Size), metadata.Get("file-size")[0])
}
// Assert Headers
metadata, err := stream.Header()
require.NoError(t, err)
require.Len(t, metadata.Get("sha3-256-checksum"), 1)
assert.Equal(t, a.Hash, metadata.Get("sha3-256-checksum")[0])
require.Len(t, metadata.Get("file-size"), 1)
assert.Equal(t, fmt.Sprintf("%d", a.Size), metadata.Get("file-size")[0])
}
}

// Run Tests
Expand Down
Loading
Loading