Due to switching to Alpine the ability to resolve mDNS
hostnames was lost. This patch overrides the lookup and
manually resolves the names.
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
We provide a local DNS server for containers to use and this
was not allowed through the firewall when enabled.
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
When invoking iptables-restore it can fail. This wasn't handled
and this makes sure that it fails gracefully.
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
The host config variable HOST_DISCOVERABILITY can be set to
true or false, controlling the state of the avahi service. This
determines if the device advertises it's presence over mDNS.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Signed-off-by: Rich Bayliss <rich@balena.io>
Controlled by BALENA_HOST_FIREWALL_MODE, the firewall can
either be 'on' or 'off'.
- In the 'off' state, all traffic is allowed.
- In the 'on' state, only traffic for the core services provided
by Balena is allowed.
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
When reporting device information, send the MAC address of any
interfaces on the system. Also expose in the Supervisor API at
the route GET /v1/device.
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
This is part of the work to make the application-manager module much
less monolithic, in preperation for system apps and more generally
multi-app.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
We were treating the database class as a singleton, but still having to pass
around the db instance. Now we can simply require the db module and have
access to the database handle.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This allows a response to an input with dport=`supevisor api port` and
is required when the host OS is doing stateful firewalling.
This should not affect things when stateful firewalling is not in
effect, as the standard OUTPUT chain policy is ACCEPT, so we're just
being explicit about it.
Change-type: patch
Backport-to: next, current, sunset
Signed-off-by: Cameron Diver <cameron@balena.io>
We add an implicit .0 to the end of l4t versions which do not fulfill
semver, which allows us to always match using comparison operators, such
as < and <=.
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
The new label `io.balena.features.sysfs` will mount the host /sys into
the container at /sys.
Relates to issue: #743
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
Bring the labels into a more declarative format and run through them to
apply the various labels and env vars.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This change will start the minimum backoff from 15s (up from 500ms) and
will use the appUpdatePollInterval configuration variable as the max.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
ConfigJson users now don't need to worry about initialization.
It's done lazily on the first public method call.
Implementation is also rewritten to follow async/await pattern.
Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
This means that if an image is created with a committed container, we
won't assume that it does not contain the balena env vars
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
A compose file can now contain a volume which uses a different driver
from the default one; local.
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Before this change a mixed device fleet with a subset using l4t would
not be able to have containers which only run on the l4t based boards.
We add a mock l4t version so the contracts will always be denied on
non-l4t boards, but the release itself won't fail to validate.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Part of device-state refactor
Fix the wrong usage of TargetState as DeviceApplicationState
Change-type: patch
Signed-off-by: Theodor Gherzan <theodor@balena.io>
Custom type definitions are removed for mixpanel module since they are embedded
into their npm package.
Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
These contracts can specify an OS version and supervisor version that
they require. If any of the containers in a release have requirements
that are not met, the release is rejected, and the previous release
continues to run.
Change-type: minor
Closes: #1086
Signed-off-by: Cameron Diver <cameron@balena.io>
This also required refactoring the request library to be generated with
a promise, as we now no longer get the information synchronously.
We also cache the release info, to avoid grabbing it again within the
same runtime, which does not make sense.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
With this change, we define a custom error handler as express middleware
which renders 503 error with JSON response that includes status and message
fields.
The handler also logs the error, so the stack can be inspected in supervisor
logs. It's also a point where we can report the error to analytics services.
This removes a bunch of error handlers written in every request handler
function. Behaviour should remain unchanged except the fact that
/healthy endpoint now returns 503 in case of failure instead of 500.
Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
If an error fires when writing to the cloud stream, it can stop any
calling processes from completing. Given that a logging failure should
not cause other processes to cancel, we catch and report the error but
otherwise do nothing else.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
The `createFromPath` method takes 3 parameters, while in a previous
version it was only 2 (the new format splits the old format's first
parameter into two, and keeping the last), before the refactor in commit
23e564389d (supervisor v9.18.4)
The backup restoration call has not been updated and thus calls that
function the old (wrong) way, resulting in failed restore, and volume
management errors on a device that attempted a restore.
Change-type: patch
Signed-off-by: Gergely Imreh <gergely@balena.io>
Various fields returned from the docker daemon don't retain order (for
example the volumes field). We now only select certain array values to
compare taking order into account.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This can cause issues where the stack is exhausted
on large applications.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Signed-off-by: Heds Simons <heds@balena.io>
The docker daemon can sometimes return null for various fields,
or omit the field altogether. The best thing to do with using
the docker api is to always use == null to cover both instances.
Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
This will throw a typed error in case when supervisor cannot inspect
its own container.
Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
With recent changes to local mode behavior, supervisor removes all engine objects
that were not present before entering local mode.
With this change, supervisor also detects its own resources and does not delete them
if it was updated during local mode operations.
Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
That way that this is performed is by first adding a depends_on entry
for the target service if it appears in a network mode. Then when we
generate the docker container for this service, we use the containerId
of the target container and replace the network_mode with
`container:<id>`.
When comparing state, we check that the containerId still points to the
contianerId of the target container, and in this way we ensure that
when a network mode target container changes, we change the dependent
container too.
Change-type: minor
Closes: #851
Signed-off-by: Cameron Diver <cameron@balena.io>
The code before this change could potentially remove a volume which
should not be removed if a container was deleted before the call that
references said volume.
To avoid this, we additionally filter the list of volumes to cleanup by
any that are referenced in the target state. This means that cleanup
will never remove it, as long as it's still supposed to be there,
regardless of if a container references it or not.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This change also makes sure that in the application-manager workflow we
pass around instances of the Volume class, rather than just the config.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Since we were comparing the VPN's value before adding the explicit "true", there were cases
were the VPN is off, and therefore "value" didn't match the default, so the supervisor would
create a device specific SUPERVISOR_VPN_CONTROL = true, which is unnecessary and causes issues if
users don't expect this and move the device to an app that has VPN disabled. The correct behavior
is to compare "varValue" and only create a device config var if this value differs from the default.
(This was the behavior before the TS conversion in 01ed7bb103 )
Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
This change makes DeviceState to wait until local mode switch is definitely
completed before actually applying the state, which avoids races in state cleanup.
Change-type: patch
Signed-off-by: Roman Mazur <roman@balena.io>
In local mode, we now update device status on the backend,
but omit applications info in our updates.
Closes: #959
Change-type: minor
Signed-off-by: Roman Mazur <roman@balena.io>
Also use the supervisor's own container logging monitoring code when
running livepush on the supervisor container.
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
Changes are collected together and exist in memory, for querying and
saving. Once every 10 mins, every changed timestamp is flushed to the
database.
Change-type: patch
Closes: #987
Signed-off-by: Cameron Diver <cameron@balena.io>
This is a massive commit, but nothing related to runtime has actually
changed, only the lint errors have changed.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Changes in the node engine related to streams would cause the gzip
streams flush function to be called at the wrong times. The sinon fake
timers were also interacting with this.
We use setImmediate to call the flush function, and remove sinon timers
for the logging tests.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Before this change the first time the cleanup code runs would be before
the migrations have had a chance to execute. This change makes it so
that the cleanup code always runs once the migrations have finished.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
When assigning multiple host ports to a single container port before
this change, the supervisor would incorrectly take only the first host
port into consideration. This change makes it so that every host port
per container port is considered.
Closes: #986
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Prior to this change, we would `_.uniq` the expose value before adding
values from the port mappings. This could cause ports to get added
twice, which would cause the supervisor to think that there is a
configuration mismatch.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
Even though this would never have attempted to report the state to the
api during local mode, it leaves behind artifacts which would cause the
state to be sometimes reported when exiting local mode. This would cause
the api to reject the update unecessarily.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This had a bug where it was using the `in` operator on a list. It may
have worked for some cases, but would have failed for others.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
We add a database table, which holds information about the last
timestamp of a log successfully reported to a backend (local or remote).
We then use this value to calculate from which point in time to start
reporting logs from the container. If this is the first time we've seen
a container, we get all logs, and for every log reported we save the
timestamp. If it is not the first time we've seen a container, we
request all logs since the last reported time, ensuring no interruption
of service.
Change-type: minor
Closes: #937
Signed-off-by: Cameron Diver <cameron@balena.io>
Container logging is now handled by a class which attaches and emits
information from the container. We add these to the directory
logging-backends/, and rename it to logging/.
Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
We also add a catch to any errors when getting configuration, and send 503 in this case, even if it's
unlikely.
Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
This commit does two related things:
* We make the poll interval a random time between 0.5 and 1.5 times the configured interval.
* We introduce the BALENA_SUPERVISOR_INSTANT_UPDATE_TRIGGER configuration variable, that defaults to true. If this variable is set
to false, then calls to /v1/update are ignored, and on startup the supervisor waits for a poll interval before getting the target state.
This will help especially on cases where there's a large number of devices on a single network. By disabling instant updates and setting a large
poll interval, we can now achieve a sitation where not all devices apply an update at the same time, which can help avoid
overwhelming the network.
Change-type: minor
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
When comparing a stopped container after a start request, the container
ID will be present in the target state (where usually it is not). We
were already filtering this value out of the current state, but
neglected to do so for the target state. This change now ensures we
remove it from both alias lists if it exists.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
In an edge case observed in the field, a supervisor's database held two applications
because the device had been moved and the update lock was set in the old app. This causes
the updated supervisor to be unable to start, logging "No compatible releases found in API",
because it can't fetch the release for the app it was moved from.
This commit changes the migration code to iterate through all apps, and remove any for which
we can't get a release.
Change-type: patch
Signed-off-by: Pablo Carranza Velez <pablo@balena.io>
Before this change, service name resolution would only occur in the
default network. This was because we were not explicitly adding aliases
of the service names to the aliases fields.
We also fix the comparison, which would do funny things based on
container IDs, which was correct but unnecessary.
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
If a value is requested which does not pass validation, we instead set
it to the default value, to ensure that the state engine continues to
work and move towards the target state.
Change-type: minor
Closes: #938
Signed-off-by: Cameron Diver <cameron@balena.io>