How to catch an ouppuit of a process or a command - docker

I'm trying to write a rule where the condition depends on the output of a script.sh. I had tried several approaches, but I did not have success.
Searching in your documentation but didn´t find anything that help me. I tried several evt or proc, but neither of them given me any info.
In fact, this is the rule with I'm trying to see how I can find a workaround:
- rule: FIM Custom rule
desc: Testing rule
condition: access_log_files and (evt.type=close)
output: Test result (proc_name=%proc.name command=%proc.cmdline evt_type=%evt.type evt.args =%evt.args syslog_.facility_str=%syslog.facility.str syslog_message=%syslog.message)
priority: WARNING
Consider please that I´m running Falco on Docker with the last image.
When I execute in the Ubuntu host the command logger test, I recievedin the stdout of the docker falco container this message:
{"hostname":"dc95654c63c3","output":"01:21:29.759239580: Warning Test result (proc_name=python3 command=python3 /usr/lib/ubuntu-advantage/timer.py evt_type=close evt.args =res=0 syslog_.facility_str= syslog_message=)","priority":"Warning","rule":"FIM Custom rule","source":"syscall","tags":[],"time":"2022-12-17T01:21:29.759239580Z", "output_fields": {"evt.args":"res=0 ","evt.time":1671240089759239580,"evt.type":"close","proc.cmdline":"python3 /usr/lib/ubuntu-advantage/timer.py","proc.name":"python3","syslog.facility.str":null,"syslog.message":null}}
So please tell me what I can do.
Thanks

In order to feed Falco with external sources of events (those that are not Kernel Syscalls) you'd need to use a Falco plugin. There are plugins to obtain events from Kubernetes, AWS CloudTrail, or even from GitHub. However, there is no plugin, that I know of, to obtain information from the standard output of a program or from Syslog.
Due to the nature of the project Falco, anyone in the community can contribute with such a plugin, so I invite you to join the Falco slack channel and ask around, or even write your own plugin.

Related

GCP Cloud run - how do I get CloudRun service parameters run-time

I have several CloudRun services running. I have the need to do some environment specific things (also because I have a docker container being built from the same sources too) in code. I searched around quite a bit to find out if I can get the following run-time:
Check if my code is running in a CloudRun instance or not
Get other environment variables like service-name, project-name, deploy-time, awake-time, region-name, etc. - for various reasons
This demo container code shows how to get that kind of information:
https://github.com/GoogleCloudPlatform/cloud-run-hello/blob/master/hello.go
Some things are available directly as environment variables like service and revision
service := os.Getenv("K_SERVICE")
revision := os.Getenv("K_REVISION")
The container contract docs page shows the full list
https://cloud.google.com/run/docs/container-contract
as well as information about the metadata server that can give you things like project-id or region.

Facing Error while running a JMeter script using docker file on AWS

Hi I am Niladri Shekhar De, relatively new to performance testing. I am trying to run my load test (scripted in JMeter) using docker file on AWS. I am editing the docker file as mentioned in docker file this picture. Also, I have edited the entrypoint as this
entry point picture. Then while I am trying to run it is waiting for long after "Waiting for possible shutdown...." line and finally I am getting all 10 errors (My script has 2 transactions and I am running for 5 users) as shown in the picturecloudwatch. The script name may be mentioned here is different than in the docker file but that I have changed later. Could anyone please look into this and help me out? It will really be a great help..
Although your way to take screenshots is fantastic you should not be posting code as images on StackOverflow
Coming back to your question: we cannot see any failure reason there so I would suggest to check:
The .jtl results file, it should have status code, response message, maybe response details, etc.
The jmeter.log file which normally can give a clue regarding what's wrong. If it doesn't - you can try increasing JMeter logging verbosity

Enable k8s experimental features in Docker Desktop

does anyone know if this is possible?
All I can find in docs is reference to enabling docker experimental features, but not the kubernetes experimental features.
I tried this, but still get error.
k alpha debug -it exchange-pricing-865d579659-s8x6d --image=busybox --target=exchange-pricing-865d579659-s8x6d
error: ephemeral containers are disabled for this cluster (error from server: "the server could not find the requested resource").
Thanks
I had the same intent (as have others in this feature request). After several hours of trial and error, I finally found out a way to do so.
Steps:
Depending on which file you're trying to edit, you may need to fully shut down Docker Desktop, and restart WSL. (right-click tray-icon and press "Quit Docker Desktop", then run wsl --shutdown, then run wsl)
Open the [...]/kubeadm/manifests folder, in the Docker filesystem.
On Windows, navigate Windows Explorer to:
For Docker Desktop 4.2.0: \\wsl$\docker-desktop-data\version-pack-data\community\kubeadm\manifests
For Docker Desktop 4.11.0: \\wsl$\docker-desktop-data\data\kubeadm\manifests
Open the kube-controller-manager.yaml, kube-apiserver.yaml, and kube-scheduler.yaml files, adding the line below:
spec:
containers:
- command:
[...]
- --feature-gates=EphemeralContainers=true <-- add this line
Start Docker Desktop again.
It looks so easy when its already figured out, huh? Well trust me, it was a pain to find out.
Some of the slowdowns I hit:
It took me quite a while to even find those manifest files. (eventually found it using grepWin, searching through the whole \\wsl$\docker-desktop-data folder for any matches of a line I grabbed from the kube-apiserver-docker-desktop pod's config, which I viewed using Lens)
Once I found it, I got confused by this documentation. When I read FEATURE STATE: Kubernetes v1.22 [alpha], I thought that meant you needed version 1.22 or higher of Kubernetes for the feature to be available. This caused a huge wild goose chase where I tried to change the version of Kubernetes that was being launched in Docker Desktop, which Docker Desktop didn't seem to like. (in retrospect, the issue may have just been the minor one in point 3 below...)
When I first made changes to the manifest files, I was using Notepad++. And despite my liking Notepad++, it's apparently not quite as smart as vscode in the following regard: it does not automatically detect the indentation type for yaml files. Thus, when I pressed tab to create an indent, so I could add the new flag to the argument list, it added it as a tab character rather than spaces. This caused Kubernetes to fail reading of the file. That might not be so bad if Kubernetes gave a sane error message for that, but instead it merely gave the message unexpected EOF. And I didn't even see that error message at first because it was not being propagated to the kube-controller-manager-docker-desktop pod (which was the only relevant one that wasn't immediately erroring/closing). Anyway, I didn't realize this was the problem at the time, so...
I decided to try bypassing the manifest-files and applying my modification to the etcd data-store directly. In retrospect, this was not a good idea, because the etcd data-store is pretty complex, the tooling is substandard, and the documentation is substandard. I spent a ton of time just trying to figure out how to send commands to read and write data to it (eventually managed to do so by calling etcdctl within the etcd-docker-desktop pod). I spent further time still writing up a NodeJS script capable of reading all the data as JSON, storing it in a dump file, and being able to write changes to entries back despite there being 3+ levels of quoting involved (I eventually was able to use stdin to pass the value rather than as part of the command string, to avoid quotation-mark-inception). After all the work on etcd reading/writing above, I found it didn't work anyway because Kubernetes invariably "breaks" if anyone else writes to its etcd data-store. (even if you write the exact same value that had been there before -- as verified by comparing the dumps before and after)
After all of the above, I decided to have one last go with just adding the flags to mentioned manifest files. Was still getting the startup failure/error, but at the very end, I decided I wanted to see exactly what about my changes was causing Kubernetes to reject them. So I tried commenting out my added line; the error remained. I thought maybe it was a checksum-based rejection then. But then I thought, maybe the YAML parser that Kubernetes is using is just outdated and is finicky about what comments it is able to recognize. So I tried moving the comment around to different places, and was puzzled when the manifest was being accepted just by moving the comment to the root level. I moved it back to various locations, with it working and not working, until I thought to try making the line "half-indented" since it's "in-between" the working and non-working versions. That's when I noticed the line had a tab as its indent. And then it hit me; are the other lines also using tabs? I checked, and nope, they were using spaces. And that's when I realized I had wasted the last few hours on something I coulda just fixed with a simple indent change.
The moral of the story for some is that YAML is a bad configuration format, because it makes it easy to make trivial errors like this. But I actually place the blame more on whatever parser Kubernetes is using for the YAML files; it is unacceptable that a YAML parser would encounter an indentation mismatch and give a message so generic as unexpected EOF. I don't know what the identity of that YAML parser is, but I'm tired enough of the subject that I'm not even going to look into it right now. If one of you finds it, please make an issue report for it -- perhaps including this story as a real-world example of the pain that ambiguous error messages can cause.
Since Ephemeral Containers is still an alpha feature, it is disabled by default.
As you can read here, for this to work, it requires the EphemeralContainers feature gate to be enabled, and Kubernetes client and server version v1.16 or later.
As to the 2nd requirement I assume both your Kuberntes server and client versions are v1.16 or later but it looks like, for the time being, the 1st requirement cannot be met on Docker Desktop. According to this issue, it currently doesn't support enabling Feature Gates.
However you may still try to ssh to your master node and edit the following files:
/etc/kubernetes/manifests/kube-apiserver.yaml
/etc/kubernetes/manifests/kube-scheduler.yaml
by adding inside the command section:
--feature-gates=EphemeralContainers=true
Then you need to delete those pods so they are recreated with new settings applied. You'll find them by running:
kubectl get pods -n kube-system

Extract lines from Kubernetes log

I'm new to kubernetes and am still trying to extract log from a few lines and write it, if anyone can help me what commands i should execute.
If the pod is named bino, and i wanted to extract the lines corresponding to the error unable-to-access-website, and then write them to a certain location, say John/Doe/bino. How would i do this is there a easy command?
I tried using kubectl log bino, but it just dumps all the output on the terminal, if i wanted to write certain parts how can i do it? Thanks!
Or if anyone has played around in katacoda i would appreciate a link to a similar example.
You can use grep in linux to fetch the relevant log messages you want:
kubectl log bino | grep "error unable-to-access-website" >> John/Doe/Bino/log.txt
Hope this helps.
If you are not that familiar with grep and regular expressions in general, then you can use the Retrospective Log Analyzer https://retrospective.centeractive.com/tutorial_monitorcontainer.html which will do the heavy regex work for you.
It makes extracting certain parts of the logs much easier, you can extract parts from log files and from container logs of Kubernetes and Docker without having to write complex regular expressions.

Unsatisfied Link Error: Flink

I was trying to run a basic program in java by submitting to the job manager in Flink. I have a native library from open CV. When I try to submit the job I get "java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path", however when I run it on eclipse by setting up the flink execution environment I get correct results.
I have followed some solutions from the apache flink support website:https://mail-archives.apache.org/mod_mbox/flink-user/201604.mbox/%3CCAO0MGUj_h==sw76-TWF6x8fnT_Vdc84mwu=YLejjn=bG-up+MQ#mail.gmail.com%3E and have modified my conf.yaml file accordingly (by pointing env.java.opts: -Djava.library.path="/path of Open CV library", but no luck,
Maybe my question is very basic , but still I am stuck, any help would be highly appreciated. Thanks :-)
I had a similar problem, often people references something like the "Tomcat" solution. Also, Flink with RocksDB writes the so to a tmp file, but this was also wrong.
If anyone else should pass this way- I wrote a short blog outlining the steps I took. OP's comment answer seems evident, but only after I also see the solution (when I was working on this, it was non-informative).
Shameless self promo:
https://rawkintrevo.org/2017/08/14/using-jnis-like-opencv-in-flink/

Resources