GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — host-api/exec/exec_admission_test.go at main · PastureStack/host-api

Expand file tree

/

exec_admission_test.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
60 lines (58 loc) · 2.19 KB
/

exec_admission_test.go

Copy path

File metadata and controls

60 lines (58 loc) · 2.19 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package exec
import (
"errors"
"github.com/PastureStack/host-api/auth"
"github.com/PastureStack/host-api/config"
"github.com/PastureStack/host-api/testutils"
"github.com/PastureStack/websocket-proxy/common"
docker "github.com/fsouza/go-dockerclient"
"os"
"path/filepath"
"testing"
"time"
)
func TestVerifiedFullKeyAuditAdmissionPreventsExecSideEffects(t *testing.T) {
prior := config.Config
defer func() { config.Config = prior }()
config.Config.ParsedPublicKey = testutils.ParseTestPublicKey()
config.Config.HostUuid = "h1"
config.Config.HostUuidCheck = true
config.Config.PlatformURL = "http://127.0.0.1:1"
config.Config.PlatformAccessKey = "agent"
config.Config.PlatformSecretKey = "secret"
for _, mode := range []string{"full", "unwritable"} {
t.Run(mode, func(t *testing.T) {
parent := t.TempDir()
if err := os.Chmod(parent, 0700); err != nil {
t.Fatal(err)
}
dir := filepath.Join(parent, "completion-spool")
config.Config.CompletionSpoolDir = dir
ticket := func(nonce interface{}) string {
return testutils.CreateTokenWithPayload(map[string]interface{}{"hostUuid": "h1", "apiKeyAudit": map[string]interface{}{"version": 1, "issuedAt": time.Now().Unix(), "fixture": nonce}, "exec": map[string]interface{}{"Container": "must-not-execute", "Cmd": []interface{}{"sh"}}}, testutils.ParseTestPrivateKey())
}
if mode == "full" {
for i := 0; i < 128; i++ {
if !auth.BeginStreamAudit(ticket(i)).Ready() {
t.Fatal("fixture could not fill exact bounded queue")
}
}
} else {
if err := os.WriteFile(dir, []byte("fixture blocker"), 0600); err != nil {
t.Fatal(err)
}
}
called := false
handler := &ExecHandler{dockerClient: func() (*docker.Client, error) { called = true; return nil, errors.New("must not reach Docker") }}
response := make(chan common.Message, 4)
handler.Handle("fixture", "/v2-beta/exec/?token="+ticket("attempt"), make(chan string), response)
if called {
t.Fatal("audit admission failure executed Docker work")
}
message := <-response
if message.Type != common.Close || message.Body != auth.AuditUnavailableWire {
t.Fatal("unavailable audit was misrepresented as permission denial")
}
})
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.