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 docs-site/src/content/docs/hosted/user/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ With the `hub.attachment_artifacts` experiment on, a file uploaded in web chat o
- **Group conversation without a project:** its current participants. Someone who joins can read the attachments of earlier messages, and someone who leaves stops being able to read them.
- **Anyone the message is addressed to.**

When the message goes to an agent, the file is delivered into that agent's own home (see [Attachments for agents](#attachments-for-agents)). For a message in a project thread, whose readers are the whole project, a copy is also placed in the project's `scratchpad` shared directory at `.attachments/_webchat/<id>/<name>`, so the project's other agents can find it (if looking up the topic fails, the Hub fails closed and skips the shared-directory copy rather than copying into the project scratchpad). Every agent and member with access to that directory can read the copy. Direct messages and group conversations are delivered only into the recipients' homes, with no shared copy. Copies are removed after `messaging.attachment_inbox_retention_days` (7 days by default). The experiment is on by default wherever the artifact service is ready, including Hubs with local storage (no object store needed), and on Hubs whose resource storage is an object store.
When the message goes to an agent, the file is delivered into that agent's own home (see [Attachments for agents](#attachments-for-agents)), with no copy placed in the project's `scratchpad` shared directory. Other agents that may read the message can fetch its attachments with `scion conversation get-message --save-attachments`. The experiment is on by default wherever the artifact service is ready, including Hubs with local storage (no object store needed), and on Hubs whose resource storage is an object store.

Until it is sent, only the uploader can read it, and an upload that is not sent within 24 hours is removed. Deleting a message makes its attachments unreadable at once, and their stored bytes are removed after the artifact garbage-collection grace period. Any user who cannot read it gets the same "not found" answer as for an attachment that does not exist. A user access token uploads, sends and reads them for its holder under its own rule: it needs `inbox:read` to read and `inbox:write` to upload and send. It reads an attachment only when its holder may read the message, and the token's boundary must reach the project recorded for the attachment: a project boundary for that project, or a hub boundary. An attachment with no project, and the holder's own upload before it is sent, need a hub boundary. In a direct message with an agent, the token also needs `agent:read` on every agent in the conversation. An attachment recorded before projects were recorded is not readable with a token. Attachments are read only through their message: they have no share links, grants or versions, and they are not listed among artifacts.

Expand All @@ -89,7 +89,7 @@ Each file can be up to the artifact file size limit (`artifacts.max_file_bytes`,
With the `hub.attachment_artifacts` experiment on, agents send and receive attachments as files:

- **Sending:** `scion message --attach <file>` first asks the Hub where uploads go. When the Hub stores attachments as artifacts (which for an agent caller also requires `project:artifact:read` on its token), the CLI checks the files, uploads them and names them in the send. Each file must be a readable regular file, no two files may have the same name, and HTML and SVG files are refused: publish one with `scion artifact publish` and send it with `--artifact`. With an agent recipient, the files must fit the delivery limit below. Any path works; the files do not need to be in a shared directory. A group send uploads the files once per recipient. If any file fails to upload, nothing is sent. When the experiment is off, or when the calling agent's token lacks `project:artifact:read` (for example when its delegation-chain ceiling withheld it, in which case `GET /api/v1/chat/attachments` answers `"legacy"` and `POST /api/v1/chat/attachments` answers `404 attachment_artifacts_unavailable`), `--attach` stages files in the shared directory as before.
- **Receiving:** an agent that may read the message gets each file at `~/.scion/inbox/<message-id>/<name>` before the message text arrives, and the message lists those paths. For a project thread the message also lists the file's copy in the project scratchpad, after the inbox path, tagged with its shared directory (`attachment_mounts` in the envelope) and described as also visible to sibling agents; use the inbox path. `<name>` is the file name with every character other than letters, digits, `.`, `_` and `-` replaced by `_`. A file that could not be delivered gets one line after the message text: `Attachment not delivered: <path> (<size>): <reason>. Ask the sender to resend it.`
- **Receiving:** an agent that may read the message gets each file at `~/.scion/inbox/<message-id>/<name>` before the message text arrives, and the message lists each attachment once at that path. `<name>` is the file name with every character other than letters, digits, `.`, `_` and `-` replaced by `_`. A file that could not be delivered gets one line after the message text: `Attachment not delivered: <path> (<size>): <reason>. Ask the sender to resend it.` Other agents that may read the message can fetch its attachments with `scion conversation get-message --save-attachments`.
- **Which agents get a file:** the agents that may read the message: a participant of its conversation, an agent of the project for a project thread, and an agent the message is addressed to, including an agent @mentioned in it. An agent in another project that is the recipient gets the file; other agents of that project do not.
- **A snapshot:** a delivered file stays in the agent's home after the message is deleted, until the agent's inbox is pruned (directories older than `messaging.attachment_inbox_retention_days`, 7 days by default) or the agent is deleted.
- **Kubernetes default pods:** the agent's home lives in the pod, so delivered files are lost when the pod is recreated. Homes on NFS, and runtimes that keep the home on the host, keep them.
Expand Down
2 changes: 1 addition & 1 deletion docs-site/src/content/docs/reference/server-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ With the `nfs` backend, the Hub and brokers also apply the following:

- **Symlink-safe access**: Every Hub operation on an NFS shared directory goes through the same confined resolver. This covers the web file browser, archive downloads, and shared-dir deletion. The resolver walks each path component with `O_NOFOLLOW`, anchored on the inode of the project's tree, and refuses any symlink in the path. A missing or incomplete `nfs` block, or an unusable host base directory, fails closed on the Hub as well as on agent start.
- **Leaf modes and ACLs**: A newly created shared directory gets mode `2775` (setgid, group-writable) and a minimal default POSIX ACL, so files agents create inside it inherit group write access regardless of umask. If the export does not support POSIX ACLs, a warning is logged once and the directory stays plain `2775` with no ACL. Files created inside such a directory follow each writer's umask (usually `022`), so they are not group-writable. Directories that already existed are never modified. See the [hybrid tier guide](https://github.com/GoogleCloudPlatform/scion/blob/main/docs/deploy/hybrid-tier.md) for the manual fix-up recipe.
- **Chat attachments**: Attachments are delivered into each recipient agent's inbox (`~/.scion/inbox/<message-id>/`) when `hub.attachment_artifacts` is on. It is on by default wherever the artifact service is ready, including the workstation server and other Hubs with local storage (no object store is needed), and on Hubs whose resource storage is an object store; a stored override still applies. For a message in a project topic thread, whose readers are the whole project, the Hub also copies each attachment into the project's `scratchpad` shared directory at `.attachments/_webchat/<id>/<name>`, and the message lists that inbox path first. It resolves the directory the same way as the file browser, so on NFS the copy lands where agents mount the scratchpad, and every write goes through the same confined resolver. The message tags the copy's container path with its shared directory (`attachment_mounts` in the delivered envelope). Attachments in direct conversations and participant-list group conversations are delivered only into the recipients' inboxes, with no shared copy, on every storage backend. An attachment that is not stored as an artifact (for example while `hub.attachment_artifacts` is turned off) has no inbox delivery. On shared storage (NFS) its scratchpad copy is likewise made only for project topic threads; a direct or group conversation's attachment is not copied there. On the workstation server (local storage) the copy is how an agent reads the file, so it is made for every message, direct conversations included. The other agents of the project can then read a direct message's attachment. This is a known limitation of that configuration, and it goes away once the Hub stores attachments as artifacts. Files an agent attaches with `scion message --attach` are read from the same directory. Scratchpad copies older than `messaging.attachment_inbox_retention_days` (default 7) are removed by the Hub's hourly maintenance pass, on every backend.
- **Chat attachments**: Attachments are delivered into each recipient agent's inbox (`~/.scion/inbox/<message-id>/<name>`) when `hub.attachment_artifacts` is on, with no copy placed in the project's `scratchpad` shared directory on any conversation type or storage backend; sibling agents that may read the message can fetch its attachments with `scion conversation get-message --save-attachments`. The experiment is on by default wherever the artifact service is ready, including the workstation server and other Hubs with local storage (no object store is needed), and on Hubs whose resource storage is an object store; a stored override still applies. An attachment that is not stored as an artifact (for example while `hub.attachment_artifacts` is turned off) has no inbox delivery and is staged into the project's `scratchpad` shared directory at `.attachments/_webchat/<id>/<name>`, tagged with its shared directory (`attachment_mounts` in the delivered envelope). On shared storage (NFS) that legacy scratchpad copy is made only for project topic threads, resolved through the same confined resolver as the file browser; a direct or group conversation's legacy attachment is not copied there. On the workstation server (local storage) the legacy copy is how an agent reads the file, so it is made for every message, direct conversations included. The other agents of the project can then read a direct message's legacy attachment. This is a known limitation of that configuration, and it goes away once the Hub stores attachments as artifacts. Legacy files an agent attaches with `scion message --attach` are read from the same directory. Scratchpad copies older than `messaging.attachment_inbox_retention_days` (default 7) are removed by the Hub's hourly maintenance pass, on every backend.
- **Ownership on an export that does not squash ids**: the broker creates the project chain as its own user and never changes ownership. Upper directories get `2755` and the leaf `2775`, and each inherits the group of a setgid parent. Pods create nothing on this export; they mount the existing leaf by `subPath`. When agents with different uids share a directory, for example Docker agents and Kubernetes pods, give the share directory (`<mount_root>/<share id>`) a shared group with the setgid bit (for example `chgrp <gid>` and `chmod 2775`) so every leaf inherits it. Scion then adds that group to each agent that mounts the leaf; see [Agent groups](#agent-groups-on-nfs-shared-directories).
- **Existing upper directories**: the expected layout for an upper directory that already exists on the export is setgid, group `nfs.gid`, not writable by others, and owned by the broker user or `nfs.uid`. An existing upper directory that is group- or other-writable or owned by another user, and does not have that layout, is left as it is and logged once per process as a warning.
- **Cleanup on delete**: Deleting a project removes its whole `<subpath_root>/<project id>` tree from the export (see [cleanup on project delete](#cleanup-on-project-delete)). Removing a single shared directory declaration deletes that directory. Both are best-effort: failures are logged and never block or roll back the database change.
Expand Down
33 changes: 1 addition & 32 deletions pkg/artifacts/attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,45 +384,14 @@ func (s *Service) MayReadAttachments(ctx context.Context, messageID string, mess
return mh.MayReadMessage(ctx, messageID, messageProjectID)
}

// OpenBoundAttachment opens the bytes of attachment artifactID, which must
// be bound to message messageID, for the host to deliver to the message's
// addressees. It checks no caller: the host calls it only from its own
// send path, after the send was authorized and the message stored, never
// on behalf of a request that names an attachment.
func (s *Service) OpenBoundAttachment(ctx context.Context, artifactID, messageID string) (io.ReadCloser, AttachmentInfo, error) {
b, ok := s.backend()
if !ok {
return nil, AttachmentInfo{}, ErrUnavailable
}
if !canonicalID(artifactID) || messageID == "" {
return nil, AttachmentInfo{}, ErrNotFound
}
a, err := b.store.GetAttachment(ctx, artifactID)
if err != nil {
return nil, AttachmentInfo{}, err
}
if a.ID != artifactID || a.ScopeKind != ScopeKindMessage || a.ScopeRef != messageID {
return nil, AttachmentInfo{}, ErrNotFound
}
f, err := attachmentFile(ctx, b, a)
if err != nil {
return nil, AttachmentInfo{}, err
}
rc, _, err := b.blobs.Download(ctx, BlobPath(b.hubID, f.SHA256))
if err != nil {
return nil, AttachmentInfo{}, fmt.Errorf("artifacts: open attachment: %w", err)
}
return rc, AttachmentInfo{ID: a.ID, Name: f.Path, MediaType: f.MediaType, Size: f.Size}, nil
}

// DeliveryRedirectTTL is the lifetime of the object-store URL a broker is
// redirected to when it redeems an attachment delivery capability
// (ptone/scion#4596).
const DeliveryRedirectTTL = 60 * time.Second

// ServeBoundAttachment answers a broker redeeming a delivery capability
// for attachment artifactID, which must be bound to message messageID
// (ptone/scion#4596). Like OpenBoundAttachment it checks no caller: the host
// (ptone/scion#4596). It checks no caller: the host
// calls it only from its capability redemption route, after the capability
// (issued under the read decision for the recipient) has been verified and
// spent. The local provider streams the bytes; an object store answers a
Expand Down
26 changes: 0 additions & 26 deletions pkg/artifacts/attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -469,31 +468,6 @@ func TestCreateAttachmentLimits(t *testing.T) {
}
}

// TestOpenBoundAttachment: the delivery opener reads only an attachment
// bound to the named message.
func TestOpenBoundAttachment(t *testing.T) {
f := newAttachmentFixture(t, false)
ctx := context.Background()
sent := f.send(userU, "msg-1", pngBytes)
up := f.upload(userU, "a.txt", "text/plain", []byte("x"))

rc, info, err := f.svc.OpenBoundAttachment(ctx, sent, "msg-1")
if err != nil {
t.Fatalf("bound attachment: %v", err)
}
b, _ := io.ReadAll(rc)
_ = rc.Close()
if !bytes.Equal(b, pngBytes) || info.Name != "shot.png" {
t.Errorf("read %q, info %+v", b, info)
}
if _, _, err := f.svc.OpenBoundAttachment(ctx, sent, "msg-2"); !errors.Is(err, ErrNotFound) {
t.Errorf("other message = %v, want ErrNotFound", err)
}
if _, _, err := f.svc.OpenBoundAttachment(ctx, up, "msg-1"); !errors.Is(err, ErrNotFound) {
t.Errorf("unsent upload = %v, want ErrNotFound", err)
}
}

// TestMessageAttachmentsAndRetireScope: history lists a message's
// attachments until the message is retired.
func TestMessageAttachmentsAndRetireScope(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/experiments/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ var compiled = []Experiment{
{
Name: AttachmentArtifacts,
Title: "Attachments as artifacts",
Description: "Stores files uploaded in web chat in the artifact service as attachments of the message they are sent in: the stored file is readable exactly by the readers of that message, and is removed when the message is deleted. It is delivered into each recipient agent's inbox; for a message in a project topic thread a copy is also placed in the project's scratchpad shared directory, where every agent and member with access to that directory can read it (direct and group conversations get inbox delivery only). Gates the hub's attachment upload path (LayerServer; it also needs the artifact service with its settings section enabled, but not hub.artifacts) and is reserved for the web surfaces that follow (LayerWeb). Attachments stored while it was on stay readable after it is turned off. Defaults on wherever the artifact service is ready, local blob storage included, and on hubs whose resource storage is an object store (GCS).",
Description: "Stores files uploaded in web chat in the artifact service as attachments of the message they are sent in: the stored file is readable exactly by the readers of that message, and is removed when the message is deleted. It is delivered into each recipient agent's inbox (~/.scion/inbox/<message-id>/<name>), with no copy in the project's scratchpad shared directory; sibling agents that may read the message can fetch it with `scion conversation get-message --save-attachments`. Gates the hub's attachment upload path (LayerServer; it also needs the artifact service with its settings section enabled, but not hub.artifacts) and is reserved for the web surfaces that follow (LayerWeb). Attachments stored while it was on stay readable after it is turned off. Defaults on wherever the artifact service is ready, local blob storage included, and on hubs whose resource storage is an object store (GCS).",
Default: false,
Layers: []Layer{LayerWeb, LayerServer},
Stage: StageAlpha,
Expand Down
11 changes: 0 additions & 11 deletions pkg/hub/attachment_delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,22 +359,11 @@ func (d *attachmentDelivery) Plan(ctx context.Context, recipient *store.Agent, d
e.State = messages.AttachmentDeliverable
e.InboxPath = attachmentInboxPath(del.MessageID, name)
}
applyProjection(&e)
plan = append(plan, e)
}
return plan
}

// applyProjection copies the delivery's scratchpad projection
// (ptone/scion#5830) onto plan entry e, which the envelope lists after the
// inbox path; a withheld recipient is told nothing about the attachment.
func applyProjection(e *messages.AttachmentPlanEntry) {
if e.State == messages.AttachmentWithheld {
return
}
e.ProjectedPath, e.ProjectedMount = e.Delivery.ProjectedPath, e.Delivery.ProjectedMount
}

// Issue returns the wire attachments of plan for one dispatch attempt to
// recipient on broker brokerID: one fresh capability per deliverable entry,
// after asking the recipient decision again. An entry whose decision
Expand Down
6 changes: 0 additions & 6 deletions pkg/hub/attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ type AttachmentRef struct {
// artifact by newArtifactAttachmentRef, for delivery into an agent's
// home. Never serialized.
sha256 string
// projectedPath and projectedMount are the container path and shared
// dir of an artifact attachment's projection into the project's
// scratchpad (ptone/scion#5827), set by stageChatAttachments on
// the send path and carried into AttachmentDelivery. Never serialized.
projectedPath string
projectedMount string
}

// AttachmentStore abstracts file storage for chat attachments.
Expand Down
Loading
Loading