Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i/prompting: add package for prompting common types/functions (canoni…
…cal#13849) * i/prompting: add package for prompting common types/functions Signed-off-by: Oliver Calder <oliver.calder@canonical.com> i/prompting: make `TimestampToTime()` return a local time, matching `time.Now()` and `time.Unix()` Signed-off-by: Oliver Calder <oliver.calder@canonical.com> i/prompting: make duration a string parsable by `time.ParseDuration()` Signed-off-by: Oliver Calder <oliver.calder@canonical.com> i/prompting: reorder functions Signed-off-by: Oliver Calder <oliver.calder@canonical.com> i/prompting: remove "app" from prompts and rules AppArmor permissions are granted by interfaces according to plugs/slots which may or may not differ between apps within a given snap. For the home interface, for example, there is never an instance where one app within a snap is granted a permission that another app in that same snap is not. Thus, it does not make sense for a rule to apply to only a single app within a snap. Instead, the interface field should optionally include the name of the plug or slot which granted the permissions, which should be received from the kernel using message tagging. The result should be of the form: `<interface name>[/<plug or slot>]` As such, rules should no longer be associated with a particular app, and in order to match, neither should request prompts. Adjustments are made to the prompting API to remove the "app" parameter when querying rules. Signed-off-by: Oliver Calder <oliver.calder@canonical.com> i/prompting: add validation functions for expiration Adds expiration-related analogues for `ValidateLifespanParseDuration` and `ValidateConstraintsOutcomeLifespanDuration`. Additionally, improves error messages by including the contents of the invalid field in the message. Signed-off-by: Oliver Calder <oliver.calder@canonical.com> i/prompting: move prompting common types/functions to interfaces/prompting Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting,snap: replace LabelToSnap with SplitSecurityTag Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: removed unused NewID function Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: removed unused CurrentTimestamp function Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: rearrange functions Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * snap: check that app is non-empty if it exists in security label Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: use time.Time for timestamp and *time.Time for expiration Since `time.Time` values are marshalled as RFC3339Nano by default, there is no reason to explicitly save timestamps and expirations as strings and convert them to `time.Time` on the fly as necessary. Let the marshaller do this automatically. As expirations should only be populated when lifespan is "timespan", expirations can be stored as `*time.Time`, which should be encoded as `nil` when empty and an expiration timestamp in RFC3339Nano format when non-empty. Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: store expiration as time.Time instead of *time.Time Additionally, adjust related error messages to remove "invalid ...:" prefix. Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: rename AsBool to IsAllow and adjust related error messages Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * snap: remove SplitSecurityTag function Instead, use the existing `ParseSecurityTag` function and then call `InstanceName` on the result. Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: remove LifespanSession There is not currently a good way to identify when a session ends when a user has logged in via multiple methods (e.g. tty, ssh). Until it is deemed to be necessary and a good implementation is developed, do not include LifespanSession. Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: validate outcome and lifespan when unmarshalling Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: remove NewIDAndTimestamp IDs used for prompting (rules and prompt requests) must be unique across reboots, and thus cannot rely on timestamps or even monotonic time. We also want IDs to be sorted, so we cannot use boot ID along with monotonic time either. Lastly, since we need IDs to be unique across reboots, we can't simply use a counter based on the maximum of the existing rule/prompt IDs. Instead, we should store the current maximum ID in memory and on disk alongside the storage of rules and prompts. This should be implemented in the respective forthcoming packages and used at the former callsights of NewIDAndTimestamp. Since IDs should no longer be tied to timestamps, we can simply use `time.Now()` where the timestamps from `NewIDAndTimestamp` were formerly used. Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: replaced ValidateLifespan* functions with methods on lifespan Signed-off-by: Oliver Calder <oliver.calder@canonical.com> * i/prompting: add doc string and adjusted error messages and comments Signed-off-by: Oliver Calder <oliver.calder@canonical.com> --------- Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
- Loading branch information