-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(#1038) Add scope start
command
#1049
Conversation
9e54b38
to
9ae1f2b
Compare
Progress for interactive commands and loading the libscope For single cmd run
The disadvantage is that the command must be prepared on the host side. For interactive login shell
Steps required to do it:
All commands executed in the shell result in preloading the For interactive shellFor the bash
Append to the For the ash (Alpine)
The solution present in a Credits to @iapaddler for investigation. |
Progress for namespace
Let's consider the following example:
flowchart LR
subgraph Host
subgraph Container A
id1["Process A"]
end
subgraph Container B
id2["Service B"]
end
id3["Process C"]
end
flowchart TB
A[Host] -->|scope filter config.file| C{Check if Process belongs to host namespace}
C -->|Process is on host namespace| D[Perform scope filter action]
C -->|Process is not on host namespace| E[Switch namespace]
E --> D
Scope attach with switching namespaces at first glance seems to work with Docker containers |
6b467ce
to
a276757
Compare
Scope attach in different namespace progress:
|
Scope attach in different namespace progress:
While attaching functionality to the Docker container works fine - the LXC container is not eager to cooperate. Several observations are mentioned below:
In Docker:
In Lxc:
|
Scope attach in different namespace progress:
After installation redis will be run as a service - but we cannot attach to it - even from the container itself.
Prevent us from attach
|
e356137
to
65db197
Compare
scope filter
commandscope start
command
ec38cdd
to
0157253
Compare
97a628b
to
21e0715
Compare
scope start
commandscope start
command
21e897e
to
7b81cc0
Compare
- add support for passing configuration file from host into the container - in `ldscope` copy the configuration file from host to container Closes #1061
cli/run/start.go
Outdated
|
||
// Validate user has root permissions | ||
if err := util.UserVerifyRootPerm(); err != nil { | ||
log.Fatal(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Fatal will actually cause an os.Exit(). might be better to stick to log.Error and return err , to maintain our pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend to call os. exit here please see that there is no point to run it further if you are not an root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then the return err
afterwards is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Your suggestion with Log.error
instead of Log.fatal
is better. With Log.fatal
I call Os.Exit
with the same value. With Log.error
I can distinguish the error with the return value. Long story short changed
- Add TODO - Fix formatting
} | ||
if (setNamespace(hostPid, "mnt") == FALSE) { | ||
goto cleanupMem; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we need a net NS and probably ipc as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH for my internal testing mnt
and pid
namespace was sufficent
static int g_debug = 0; | ||
|
||
static void | ||
setEnvVariable(char *env, char *value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have a utility func that sets an env var. utils.c:fullSetenv(). can that be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think so: FullSetenv
is doing the operation based on g_fn
structure.
setEnvVariable
(or more generally loaderop module) is doing the operations in the context of our loader (ldscope) where we g_fn
is not available.
*/ | ||
|
||
static int | ||
get_dir(const char *path, char *fres, size_t len) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be a generally avail func in utils.c, like getpath()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH the code here was moved from scope_static.c
with the intention to share some logic between modules e.g. function loaderOpPatchLibrary
used in ns.c
See commit d5badd8 for details
} | ||
|
||
char * | ||
loaderOpGetLoader(const char *exe) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are all of these funcs moved? are they used in multiple places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With scope start
: one of the first operations which I perform is copying the libscope.so
to the well-known location on the host and on the containers.
For the container part, I use the code presented in the ldscope
as a --configure
. If the container is a musl-based distro (e.g. Alpine) I need to perform patching of the libscope.so
.
Therefore after copying the libscope.so
from a host into a container I need to perform a patching operation. I do not perform patching via ldscope --patch
. I patch the libscope.so
with function loaderOpPatchLibrary
.
The function loaderOpPatchLibrary
is used in multiple places: in ldscope
and in setup.c
. The rest of the code is moved here since it is needed for the loaderOpPatchLibrary
logic.
I limit the visibility of loaderOpSetLibrary
and loaderOpSetLibrary
- `loaderOpSetLibrary` and `loaderOpSetLibrary`
TODO:
attach
andservice
SCOPE_CONF_PATH
during attach from host to container #1086Question:
/etc/scope/<service_name>/scope.yml
or point to a new yml file locationNext steps:
Interactive process:
docker exec -it
local/remote login/command run
Ensure that our library is loadedFuture Improvements
scope attach
from host perspective?scope ps