mirror of
https://github.com/floci-io/floci.git
synced 2026-11-25 23:00:59 -05:00
IoT carried its own policy-variable pass. Before handing the attached documents
to the evaluator, IotService walked each statement's parsed tree, replaced the
connection's ${iot:...} values in every string it found, and dropped any
statement that still held a ${...}. That was IoT's copy of the mechanism the
evaluator gained for every other policy Floci reads, so the documents now go in
as written and PolicyVariableResolver does the substituting, from the same
condition context the connection already supplies.
The developer guide gives IoT no policy language of its own to justify a second
reader: AWS IoT Core policies "are JSON documents. They follow the same
conventions as IAM policies", they "follow the same policy evaluation logic as
IAM policies", and a policy variable is one "that can be used in AWS IoT Core
policies in the Resource or Condition block". The predefined ${*}, ${?} and
${$} are documented by pointing at IAM's own variables page.
Five corners move, each of them onto what those pages say:
- A ${...} outside Resource and Condition is text. The text pass substituted
into every string of the statement, Action and Sid included, where the guide
gives a variable meaning in those two elements only.
- ${*}, ${?} and ${$} resolve to the characters they stand for. Any statement
holding one used to be dropped, the unresolved-variable scan being a plain
\$\{[^}]*\} that matched them too.
- A variable resolves whatever case its key is written in, the variables page
being explicit that "Key names are case-insensitive. For example,
aws:CurrentTime is equivalent to AWS:currenttime". A thing attribute spelled
two ways in one registry now collides on that reading, which is the price of
the IAM rule and not a surprise unique to IoT.
- An unresolvable variable in a Condition value leaves the value null rather
than taking the whole statement away, so a positive operator does not match
and a negated one does. A Resource pattern holding one still matches no
resource, which is what dropping the statement amounted to.
- Variables need the version that introduced them. A document that does not
declare "Version": "2012-10-17" keeps ${iot:ClientId} as literal text, the
guide's answer being that "if you don't set the Version to 2012-10-17 or
later, variables like ${aws:username} are treated as literal strings in the
policy". Every policy example in the IoT guide declares it.
A connection no longer rewrites the document it evaluates, which the evaluator's
parse cache notices: it is keyed by document text, so it held one entry per
client id where it now holds one per policy.
Five tests in IotServiceDeviceAuthTest cover the five corners, and the
unresolved-variable, JSON-syntax and thing-attribute tests already there cover
what has to stay put. docs/services/iot.md says what resolves where.