Skip to content

Orbit spring cleaning#90

Merged
theyoyojo merged 28 commits into
masterfrom
orbit_spring_cleaning
May 2, 2024
Merged

Orbit spring cleaning#90
theyoyojo merged 28 commits into
masterfrom
orbit_spring_cleaning

Conversation

@charliemirabile

Copy link
Copy Markdown
Contributor

A bunch of changes that occurred to me as I had to wade through most of the code in orbit in order to switch to the ORM. Depends on #89.

@theyoyojo theyoyojo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good stuff. some small comments. tests pass locally

Comment thread orbit/hyperspace.py
Comment thread orbit/hyperspace.py
Comment thread orbit/hyperspace.py
Comment thread test.sh Outdated
Comment thread orbit/hyperspace.py Outdated
Comment thread test.sh Outdated
Comment thread test.sh Outdated
Comment thread test.sh Outdated
Comment thread test.sh Outdated
Comment thread test.sh Outdated
Given that almost all the callers are using get=True, why
even have a get parameter at all. Callers can just wrap a
call to this function in a call to print to get the behavior
of get=False.
Unclear when this would ever be useful (maybe it was added because
we used to need to manually edit the synapse db to change passwords?)
A relic of a previous attempt at a dashboard that never was.
unclear when this ever was or will be useful.
It is unclear what this option offers that cannot be achieved
by piping the output of roster through grep.
unclear when this would be useful.
unclear when this would be useful when you can just try
logging into the website to test the credentials.
The previous approach of printing 'null' or equivalent under error
conditions was fallible (consider a user with username null), and not
friendly for use in scripts (should exit with nonzero code if error
occurred)

Instead, for queries that take an action, nothing is printed and the
script exits with zero in the happy case, or an error is printed to
stderr and the script exits with a nonzero exit code.
We can just directly show the help output from the arg parser
instead of prompting the user to do it themselves with `-h`.
If a command requires more than one argument, list all of the
required arguments that are missing instead of only the first one.
the standard library secrets package contains useful functions
that can replace the logic we were using for generating tokens.

This approach is more secure too because the tokens generated by
the previous approach could be brute forced (given a username, and
knowing that the token is only good for 3 hours there are finitely
many inputs to hash function, the one we were using (SHA256) is
designed to be fast to compute which is not what you want for a
cryptographically secure hash function i.e. you want slow). A spoofed
token could be tested against the website and if a match was found,
used to hijack a logged in session.
string already supports `.encode` and bytes already
support `.decode`. Introducing new helpers only makes
things more confusing.
The decode method is shorter and consistent with the rest of the code.
utf-8 is the default option for encoding and decoding, so mentioning
it only makes the code longer without subtantially improving the clarity.
This variable is only used one place and just inserted into
a different string unconditionally so its inclusion is just
more confusing than helpful.
That way, we can use f-strings instead of
the old and unpleasent `%` string formatting.
The string is only used one place and
putting it in the function means that
an f-string can be used which is nicer.

Also fix the spacing (wasn't indented),
and the closing tags (h1 vs h3 mismatch).
It is only used in one place so just putting it there is nicer.
It is only used in one place and it doesn't even work correctly
(missing newlines after each row). We can just write the single
table that we want to generate manually and use an f-string too.
`token` and `expiry` were not used anywhere. Accessing
their values only really makes sense if you already know
that session is valid, in which case you can just do
.session.{token,expiry} which is probably clearer.
We aren't using any special versions or exotic packages. Just
installing the appropriate global python packages from `apk` is
easily adequate to get the dependencies for orbit, and it makes
all of the invocations more simple because we do not need to enter
a virtual environment anymore since the packages are global.
Since we don't have a venv anymore, we don't need {,dev-}requirements.txt
While we are at it, we can remove the old orbit readme which was an
artifact of it being a separate repo. The instructions are now out of date
and they have been superseded by the main readme.

We also do not need the dockerignore file since the orbit db has not
been stored in the orbit folder in a long time.
There are lots of absolute paths scattered around the orbit codebase.
By just setting the workdir to the location of the orbit source folder
within the Containerfile most of those paths can be converted into
relative paths which makes moving the orbit source code easier.
This makes them consistent with the other `Containerfile`s.
The source code and configuration files can be owned by root because
user 100 can still read them. Only the orbit db which needs to be
modified by the running container ought to be owned by user 100.

This adds an additional layer of security since the code on disk cannot
be modified without a privilege escalation to the container root user.

Fixes: acf767b ("orbit: switch to non-root user within container")
Instead of copying a bunch of files into the first build stage that
are otherwise unused except to copy them from build stage into the
final image, just copy directly into the final stage.
Instead of creating a nonstandard orbit directory in the filesystem
root, we can put the orbit folder within `/usr/local/share`, a standard
location for architecture independent data (e.g. python source code) as
specified in the FHS.
@charliemirabile charliemirabile force-pushed the orbit_spring_cleaning branch from 57b89af to f1515af Compare May 1, 2024 21:16
@charliemirabile charliemirabile requested a review from theyoyojo May 1, 2024 21:18
Comment thread orbit/radius.py
Comment thread orbit/radius.py

@theyoyojo theyoyojo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 small comments

@theyoyojo theyoyojo merged commit 22b9fe4 into master May 2, 2024
@theyoyojo theyoyojo deleted the orbit_spring_cleaning branch May 2, 2024 21:27
@charliemirabile charliemirabile mentioned this pull request May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants