Repository navigation
Conversation
c49c5b2 to
177fdb4
Compare
|
Rebased onto the current #3744 head (adds its apitool example/annotation fix); the last commit is still the one to review. |
177fdb4 to
28ce447
Compare
f688b13 to
946bcba
Compare
hajiler
left a comment
There was a problem hiding this comment.
Adversarial review of the logic introduced in this PR (focusing on security, failure/recovery bugs, validation, and code/comment health). Inline comments cover:
deleteActorVolumes(volumes.go:253,volumes.go:256): UnconditionalDeleteExternalVolumecan delete an unrelatedExternalVolumerecord (including after"record naming other storage fails the volume"), and when the actor status write fails afterrecordExternalVolume, falling back toactorVolumeIDpasses the CSI request name rather than the recordedVolumeIdtoDeleteVolumebefore deleting the only copy ofresp.VolumeID.createActorVolumes/recordExternalVolume(volumes.go:163,volumes.go:211):ExternalVolumerows are written to Postgres without runningapivalidation(wheredriver_namehas stricter bounds thanExternalVolumeStatus.volume_typeand CSI responses are unvalidated),store.ErrVolumeRegisteredsurfaces ascodes.Internal, andVolumeContextis not checked when reusing an existing record.- API & docs (
ateapi.proto,csi-volumes.md,combinedvolumes_test.go):ObjectRefvsstring external_volume_nameperapi-style-guide.md§2.3, proto doc-comment conventions, leftover client-only lifetime wording in docs, and assertingVolumeContextin e2e.
| recordName = provisionedExternalVolumeName(actorUID, vol.GetName()) | ||
| } | ||
| volumeRef := resources.ExternalVolumeRef{Atespace: actor.GetMetadata().GetAtespace(), Name: recordName} | ||
| if _, err := volumeStore.DeleteExternalVolume(ctx, volumeRef, store.DeletePreconditions{}); err != nil && !errors.Is(err, store.ErrNotFound) { |
There was a problem hiding this comment.
DeleteExternalVolume here deletes volumeRef by name alone with empty DeletePreconditions{} and without checking that the stored ExternalVolume actually records this actor's volume.
Two cases delete a record this actor does not own:
- Right after
TestCreateActorVolumes's"record naming other storage fails the volume"case (volumes_test.go:358-377),team-a/<derived>records"somebody-elses-disk"whilevol.StorageVolumeIdandvol.ExternalVolumeNamestay empty on the actor. CallingDeleteActorto clean up that actor (or deleting an actor that was never resumed while<derived>exists) derivesrecordNameand deletes"somebody-elses-disk"'sExternalVolumerecord. - After an actor resumes, if its
ExternalVolumerecord is deleted viaDeleteExternalVolume(asdocs/guides/csi-volumes.md:136notes) and a global owner registers another volume under the same name,DeleteActordeletes the new volume'sExternalVolumerecord.
When vol.GetStorageVolumeId() != "", read stored first, verify stored.GetDriverName() == vol.GetVolumeType() && stored.GetVolumeId() == vol.GetStorageVolumeId(), and pass store.DeletePreconditions{UID: stored.GetMetadata().GetUid()} to DeleteExternalVolume.
| // derived name when the status does not name it. | ||
| recordName := vol.GetExternalVolumeName() | ||
| if recordName == "" { | ||
| recordName = provisionedExternalVolumeName(actorUID, vol.GetName()) |
There was a problem hiding this comment.
When the actor write after recordExternalVolume fails (or ateapi crashes in between), vol.GetStorageVolumeId() is still "", while the ExternalVolume at provisionedExternalVolumeName(actorUID, vol.GetName()) holds the real resp.VolumeID returned by CreateVolume.
Because line 233 falls back to volID = actorVolumeID(actorUID, vol.GetName()) (which is CreateVolumeRequest.Name, not the driver-assigned VolumeId, e.g. "substrate-..." vs MockVolumePlugin's "mock-vol-substrate-...", "nfs-server#...", "projects/.../disks/...", or "vol-..."), plugin.DeleteVolume(ctx, volID) misses the real volume: if the driver returns NotFound, line 256 then deletes the ExternalVolume record, erasing the only persisted copy of resp.VolumeID and leaking the volume (or if the driver returns InvalidArgument on a malformed volume ID, DeleteActor is stuck). TestDeleteActorVolumes (volumes_test.go:631) masked this by seeding record(derived, "substrate-actor-uid-123-vol1") instead of "mock-vol-substrate-actor-uid-123-vol1".
Note a security subtlety if reading stored.GetVolumeId() when vol.GetStorageVolumeId() == "": deleteActorVolumes must not blindly pass an unverified stored.GetVolumeId() to plugin.DeleteVolume, or an atespace editor deleting an unresumed actor when <derived> was registered by a global owner for "somebody-elses-disk" would destroy "somebody-elses-disk" in the storage backend. Persisting StorageVolumeId on actor.Status before creating the ExternalVolume record avoids both issues: vol.GetStorageVolumeId() == "" then guarantees Substrate never wrote <derived>, and createActorVolumes can also reject a pre-existing <derived> before plugin.CreateVolume provisions an unrecorded disk.
hajiler
left a comment
There was a problem hiding this comment.
This review was produced by an AI agent (Jetski) run by the PR author.
Adversarial pass over the last two commits (935ea3c, 946bcba) only. I found two new problems. If the record write fails after CreateVolume, the volume handle is lost and the disk can leak. During a roll or rollback, an older ate-api-server deletes actors without deleting their records. The earlier inline threads on this PR are all still open at this head and are not repeated here. go build, go test -race ./cmd/ateapi/..., apitool validate, proto-breaking, codegen, gofmt, go-modules and licenses all pass. Cross-PR, outside the diff. (1) The first commit no longer matches #3744's head: patch-id 57e10859 vs c85dfa74. #3744 has since moved to maxBytes bounds and a NUL check on volume_context, dropped ifDisabled on CreateExternalVolumeRequest, added UNIQUE (record_atespace, record_name) and reworded several docs. The last two commits rebase onto c0a3d7b without conflicts. (2) The last two commits use the old actor-side name ExternalVolumeStatus in volumes.go (createActorVolumes and deleteActorVolumes signatures), volumes_test.go, validation_test.go and the ExternalVolume proto comment. Each needs the Actor prefix after #4021. (3) Field numbers do not collide across #3744, #3745 and this PR. The same reference is ObjectRef external_volume in #3745 but string external_volume_name here. Commit messages, outside the diff: 946bcba says it renames "the maxPrefix variable ... which shadowed the builtin max". It renamed max to maxPrefix. It also says "Validate external_volume_name's format", but the commit only adds tests for validation 935ea3c added.
| // A client registers a volume that already exists in the storage system. | ||
| // Substrate records one for every volume it provisions for an actor from | ||
| // `ExternalVolumeTemplate`, named in the actor's | ||
| // `ExternalVolumeStatus.external_volume_name`, and deletes it with the actor. |
There was a problem hiding this comment.
"deletes it with the actor" only holds once every ate-api-server replica runs this code. During the roll, or after a rollback (version-skew-policy.md), an older replica's DeleteActor deletes the storage and leaves the record. The record keeps its external_volume_keys row and, through ON DELETE RESTRICT, makes DeleteAtespace fail with FAILED_PRECONDITION. If the older release predates #3744, no API can remove the record. Either soften this sentence and note it in the description, or have a newer server remove records whose actor no longer exists.
| return f.externalVolumeStore.DeleteExternalVolume(ctx, volumeRef, precondition) | ||
| } | ||
|
|
||
| func TestCreateActorVolumesRecordErrors(t *testing.T) { |
There was a problem hiding this comment.
AGENTS.md prefers rows in an existing table test. TestCreateActorVolumes already has an existing field, and a store failingExternalVolumeStore column would take these two rows. The rows also use only a generic connection reset. store.ErrVolumeRegistered, the store error that can actually happen here, has no row.
An ExternalVolume is an atespace-scoped record of a CSI volume that already exists in the storage system: the driver, the volume ID and the volume context the node plugin needs to mount it. Its lifetime is independent of any actor, and an atespace cannot be deleted while it holds one. This adds the resource, its Postgres table and store methods, the OpenFGA type and RPC permissions, the Create, Get, List and Delete RPCs, and the kubectl-ate commands. Create requires the ExternalVolumes preview gate and a global owner. Get, List and Delete work with the gate off, so turning it off cannot strand a record. Delete removes the record and leaves the storage in place. Nothing references an ExternalVolume yet. Actor templates still provision a volume per actor from external.template. Signed-off-by: Elijah Rodriguez-Beltran <elijahrb@google.com>
Every volume provisioned for an actor from external.template now has an ExternalVolume in the actor's atespace, named in the actor's ExternalVolumeStatus.external_volume_name. The record is written right after CreateVolume returns and deleted by the actor's delete workflow after the storage, so a retry after a crash in between converges: the retried CreateVolume returns the same volume and the record it left is reused when it names that volume. The actor status keeps its copy of the volume handle, so resume, suspend and delete read nothing new. The record name is the volume name with a hash of the actor UID and volume name, which keeps it a DNS label and unique across actors and across a namesake created after the actor is deleted. Actors provisioned before this change have no record, and deleting them tolerates that. Signed-off-by: Elijah Rodriguez-Beltran <elijahrb@google.com>
Cover a failed storage delete keeping the record, a volume already gone from storage still losing its record, and store errors while recording or deleting one. Validate external_volume_name's format and update rules. The partial-failure functional test checks that only the provisioned volume gets a record and that none is left after delete. Rename the maxPrefix variable in provisionedExternalVolumeName, which shadowed the builtin max. Note in the resource model that Substrate writes ExternalVolumes too.
Validate the record before writing it, since ExternalVolume.driver_name is shorter than ExternalVolumeStatus.volume_type and the volume ID and context come from the CSI driver unchecked. A volume already registered under another ExternalVolume fails the resume with FailedPrecondition instead of Internal, and a leftover record is only reused when its volume context matches too. Docs and proto comments scope the delete-with-the-actor rule to volumes Substrate provisioned. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ExternalVolumeStatus.external_volume replaces external_volume_name, as the API style guide asks for cross-resource references. Callers can pass it straight to GetExternalVolume. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
946bcba to
325fe49
Compare
Part of #1637. Stacked on #3744: the first commit is that PR, review the second (
ateapi: record each actor-provisioned volume as an ExternalVolume). I will rebase ontomainonce #3744 merges.Moves the per-actor volume bookkeeping onto the
ExternalVolumeresource without changing what an actor mounts: still one volume per actor, provisioned fromexternal.template, deleted with the actor.ExternalVolumein the actor's atespace right afterCreateVolumereturns, and names it in the newstatus.externalVolumes.volumes[].externalVolumeName. The status keeps its copy of the handle, so the hot paths read nothing new.FAILED_PRECONDITION.<volume>-<hash of actor UID and volume>: deterministic, unique across actors and recreations, and within a DNS label whatever the volume name's length.Known gap until actor references land:
DeleteExternalVolumedoes not yet refuse a record a live actor provisioned. The actor keeps working from its status copy and its delete still removes the storage.AI use: drafted with an AI agent under my direction.
hack/verify-all.sh,apitool validate,hack/verify/proto-breaking.sh. The e2e sub-testcombinedvolumes/ExternalVolumeRecordedis new and has not been run on a cluster yet.