Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

share: strip content for an unreadable system privacy mode without claiming a connection

shukieshah825e40260d31
diff --git a/cli/beacon/cmd/share.go b/cli/beacon/cmd/share.go
index 9d49d118..fe76a12d 100644
--- a/cli/beacon/cmd/share.go
+++ b/cli/beacon/cmd/share.go
@@ -905,11 +905,12 @@ func shareHasProjectable(events []schema.Event) bool {
}
// shareMetadataOnly reports whether this endpoint forwards to Beacon Cloud in Metadata-only mode
-// (user or system mode). A share from it then leaves out what forwarding leaves out, so publishing a
-// session never sends more than the endpoint's privacy mode allows.
+// (user or system mode), or has a system-mode privacy mode this user cannot read. A share then
+// leaves out what forwarding leaves out, so publishing a session never sends more than the
+// endpoint's privacy mode allows.
func shareMetadataOnly() bool {
- connected, mode := shareAutoCloud()
- return connected && mode == managedprivacy.MetadataOnly
+ _, mode := shareAutoCloud()
+ return mode == managedprivacy.MetadataOnly
}
func buildSharePayload(subject shareSubject) (sharePayload, error) {
diff --git a/cli/beacon/cmd/share_auto.go b/cli/beacon/cmd/share_auto.go
index e2a1aeb8..07ecb071 100644
--- a/cli/beacon/cmd/share_auto.go
+++ b/cli/beacon/cmd/share_auto.go
@@ -26,8 +26,9 @@ import (
// to Beacon Cloud the setting does nothing but write that event; enable says so.
// shareAutoCloud reports whether this endpoint forwards to Beacon Cloud (user or system mode) and
-// with which privacy mode. Sharing strips content when the mode is Metadata-only, so whenever the
-// mode cannot be read it is reported as Metadata-only rather than Standard. A seam for tests.
+// with which privacy mode. Sharing strips content whenever the mode is Metadata-only, connected or
+// not, so a mode that cannot be read is reported as Metadata-only rather than Standard, and a
+// connection that cannot be confirmed as not connected. A seam for tests.
var shareAutoCloud = func() (connected bool, privacyMode string) {
for _, userMode := range []bool{true, false} {
if asymptote.Connected(userMode) {
@@ -63,19 +64,19 @@ func recordedPrivacyMode(value string) string {
// see. The system enrollment is in a directory only root can read, so `beacon share`, `--follow`
// and the git pre-push hook, which run as the signed-in user, get a permission error where root
// would find it. The managed_ingest block of the system config.json, which everyone can read, then
-// says whether the endpoint forwards and in which privacy mode, and a config that cannot be read
-// either counts as a Metadata-only connection.
+// says whether the endpoint forwards and in which privacy mode. A config that cannot be read either
+// (it is 0600 when it holds a HEC token) confirms no connection but still yields Metadata-only.
func unreadableCloudConnection(enrollmentPath, configPath string) (bool, string) {
if _, err := os.Stat(enrollmentPath); !errors.Is(err, fs.ErrPermission) {
return false, ""
}
data, err := os.ReadFile(configPath)
if err != nil {
- return true, managedprivacy.MetadataOnly
+ return false, managedprivacy.MetadataOnly
}
var cfg endpointconfig.Config
if err := json.Unmarshal(data, &cfg); err != nil {
- return true, managedprivacy.MetadataOnly
+ return false, managedprivacy.MetadataOnly
}
if cfg.ManagedIngest == nil || !cfg.ManagedIngest.Enabled {
return false, ""
@@ -281,19 +282,21 @@ func buildShareAutoStatus(path string, settings shareauto.Settings, dir string)
decision := shareauto.Resolve(settings, dir)
connected, mode := shareAutoCloud()
status := shareAutoStatus{
- SettingsPath: path,
- Directory: dir,
- Enabled: decision.Enabled,
- Visibility: decision.Visibility,
- Source: decision.Source,
- Project: decision.Project,
- UntrustedMarker: decision.UntrustedMarker,
- Overridden: decision.Overridden,
- UserEnabled: settings.Global() == shareauto.GlobalOn,
- UserState: settings.Global(),
- UserVisibility: settings.Auto.Visibility,
- CloudConnected: connected,
- CloudPrivacyMode: mode,
+ SettingsPath: path,
+ Directory: dir,
+ Enabled: decision.Enabled,
+ Visibility: decision.Visibility,
+ Source: decision.Source,
+ Project: decision.Project,
+ UntrustedMarker: decision.UntrustedMarker,
+ Overridden: decision.Overridden,
+ UserEnabled: settings.Global() == shareauto.GlobalOn,
+ UserState: settings.Global(),
+ UserVisibility: settings.Auto.Visibility,
+ CloudConnected: connected,
+ }
+ if connected {
+ status.CloudPrivacyMode = mode
}
for _, p := range settings.Projects {
status.Projects = append(status.Projects, shareAutoProject{
diff --git a/cli/beacon/cmd/share_auto_test.go b/cli/beacon/cmd/share_auto_test.go
index 38f1cbee..b1430cf4 100644
--- a/cli/beacon/cmd/share_auto_test.go
+++ b/cli/beacon/cmd/share_auto_test.go
@@ -223,8 +223,9 @@ func TestShareAutoRepositoryOptOutOverridesAProjectEnable(t *testing.T) {
}
// A system-mode connection keeps its enrollment in a directory only root can read. A share run as
-// the signed-in user must still find a Metadata-only connection there, and must count one it
-// cannot read at all as Metadata-only, or it would upload content forwarding withholds.
+// the signed-in user must still find a Metadata-only connection there, and must treat a mode it
+// cannot read at all as Metadata-only, or it would upload content forwarding withholds, without
+// claiming a connection it could not confirm.
func TestUnreadableCloudConnectionFailsClosed(t *testing.T) {
testenv.RequirePOSIXFileModes(t)
if os.Geteuid() == 0 {
@@ -255,8 +256,8 @@ func TestUnreadableCloudConnectionFailsClosed(t *testing.T) {
{"connect from before privacy modes", `{"managed_ingest":{"enabled":true}}`, true, managedprivacy.Standard},
{"unknown mode", `{"managed_ingest":{"enabled":true,"privacy_mode":"redacted"}}`, true, managedprivacy.MetadataOnly},
{"not connected", `{"user_mode":false}`, false, ""},
- {"config not valid JSON", `{`, true, managedprivacy.MetadataOnly},
- {"no config", "", true, managedprivacy.MetadataOnly},
+ {"config not valid JSON", `{`, false, managedprivacy.MetadataOnly},
+ {"unreadable config", "", false, managedprivacy.MetadataOnly},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {