Skip to content

Blog

Podman Volumes and SELinux## SELinuxSecurity-Enhanced Linux (SELinux) is a security architecture for Linux systems that allows administrators to have greater control over who can access the system [What is SELinux?]. For a detailed description of SELinux, refer to [SELinux Policies and Rules].


tags: - SELinuxcategories: - Linux - Containerdate:created: 2022-06-02# updated: 2024-01-19—

Podman Volumes and SELinux## SELinuxSecurity-Enhanced Linux (SELinux) is a security architecture for Linux systems that allows administrators to have greater control over who can access the system [What is SELinux?]. For a detailed description of SELinux, refer to SELinux Policies and Rules.

Section titled “Podman Volumes and SELinux## SELinuxSecurity-Enhanced Linux (SELinux) is a security architecture for Linux systems that allows administrators to have greater control over who can access the system [What is SELinux?]. For a detailed description of SELinux, refer to SELinux Policies and Rules.”

1. Problem IntroductionWhen Podman is running on a system with SELinux enabled and Volumes need to be mapped, permission issues will be encountered.

Section titled “1. Problem IntroductionWhen Podman is running on a system with SELinux enabled and Volumes need to be mapped, permission issues will be encountered.”

When running a podman container as a non-root account, files in the/home/user/directory may have the following context permissions:unconfined_u:object_r:data_home_t:s0, but podman volumes require such permissionssystem_u:object_r:container_file_t:s0to function properly. Container volumes created by podman at runtime will automatically have the appropriate context set. However, for the/home/user/directory volume, podman does not change the context by default.

2. Auto Labelspodman provides two labels for modifying the security context at runtime::zand:Z

Section titled “2. Auto Labelspodman provides two labels for modifying the security context at runtime::zand:Z”
  • Shared Labels- Private Labels Shared Labels allow multiple containers to access a volume at the same time; Private labels only allow specific containers to access the volume.

[2]. https://m-zhoujie2.gitbooks.io/-linux-devops-2/content/chapter3-10.html

[3]. SeLinux-a preliminary study

Qmake Pro

| —–– | ––––––––––––––––––– | |app|Create a Makefile for building the application (default)| |lib|Create a Makefile for building the library| |subdirs|Create a Makefile for building the target subdirectory specified by the SUBDIRS variable| |aux|Create a Makefile that doesn’t create anything|

2. TARGETSpecify the name of the target file## 3. CONFIG

Section titled “2. TARGETSpecify the name of the target file## 3. CONFIG”
release The project is built in release mode. If debug is also specified, the last one will take effect.
debug Project is built in debug mode
debug_and_release The project is ready to be built in two modes: debug and release.
debug_and_release_target This option is set by default. If debug_and_release is specified, the final debug and release are created in different directories.

Specify the Qt module used in the project. By default, QT includes core and gui. If you create a module that does not include gui, “QT _= gui”

Program compilation is a dependent path## 6. INCLUDEPATH
The include path of the header file specifies the #include directory that should be searched when compiling the project. If it contains spaces, “” should be used## 7. QMAKE_LFLAGS
Specifies a common set of identifiers passed to the linker## 8. LIBSSpecify a list of libraries to link to in the project

Reverse Proxy with Nginx on RHEL

This article introducing a method on reverse proxy with Nginx web server on RHEL.

sudo dnf install nginx
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}

(2). Site Config in /etc/nginx/conf.d/*.conf

Section titled “(2). Site Config in /etc/nginx/conf.d/*.conf”
server {
server_name WEB.DOMAIN.com;
location / {
proxy_ssl_server_name on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass http://$host:$remote_port;
}
listen 443 ssl http2; # DO NOT NEED IF YOU USE NGINX
ssl_certificate path/to/certificate/fullchain.pem; # DO NOT NEED IF YOU USE NGINX
ssl_certificate_key path/to/certificate//privkey.pem; # DO NOT NEED IF YOU USE NGINX
}
sudo dnf install certbot
sudo dnf install python3-certbot-nginx

(3). (Opt.) Install plugin for dns-cloudflare

Section titled “(3). (Opt.) Install plugin for dns-cloudflare”
sudo dnf install python3-certbot-dns-cloudflare

According to steps above, there are many ways to get certificate. We demonstrate 2 ways matchs steps (2) and (3) before.

  1. Sign with Nginx

    sudo certbot --nginx -d domainname.com

    In this way, Certificates will be configured in *.conf in folder /etc/nginx/conf.d/ automatically.

  2. Sign with dns-cloudflare

    sudo certbot certonly --dns-cloudflare \
    --dns-cloudflare-credentials \
    ~/.secrets/certbot/cloudflare.ini \
    -d example.com

    In this way, you need a cloudflare key file: cat cloudflare.ini

    # Cloudflare API credentials used by Certbot
    dns_cloudflare_api_token = 0123456789abcdef0123456789abcdef01234
sudo setsebool -P httpd_can_network_connect 1

[1]. https://certbot.eff.org/

[2]. https://certbot-dns-cloudflare.readthedocs.io/en/stable/

[3]. https://docs.nginx.com/

[4]. https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx

[5]. Let-Encrypt-with-Certbot

[6]. SElinux-初探

[7]. RHEL9-Activation

[8]. RHEL9-RPM-Fusion-Repo

Set Raspberry as WiFi Router


tags: - Raspberrycategories: - Linuxdate:created: 2020-08-11# updated: 2024-01-19—

Convert Raspberry Pi 3B+ into a wifi wireless router Implement the following functions: 1. WiFi works in 802.11ac mode, 433Mbps Link Speed 2. WiFi network sharing Ethernet port, IPv4 uses NAT 3. External USB driver-free network card as LAN port

sudo apt-get update && upgrade
sudo apt-get install hostapd dnsmasq
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p

3. Configure a static IP for the network cardNeed to ensure that /etc/network/interface is not used to configure the network card

Section titled “3. Configure a static IP for the network cardNeed to ensure that /etc/network/interface is not used to configure the network card”
sudo vim /etc/dhcpcd.conf

(2) Add the following content at the end of the file, save and exit

Section titled “(2) Add the following content at the end of the file, save and exit”
interface eth0
interface wlan0
static ip_address=192.168.3.1/24
nohook wpa_supplicant
interface eth1
static ip_address=192.168.4.1/24
nohook wpa_supplicant
sudo systemctl restart dhcpcd.service
  • eth0 automatically obtains an IP address, and wlan0 and eth1 are set to 192.168.3.1 and 192.168.4.1 respectively.
sudo vim /etc/dnsmasq.conf

(2) Add the following content at the end of the file, save and exit

Section titled “(2) Add the following content at the end of the file, save and exit”
interface=wlan0
dhcp-range=192.168.3.100,192.168.3.200,255.255.255.0,24h
interface=eht1
dhcp-range=192.168.4.100,192.168.4.200,255.255.255.0,24h
sudo vim /etc/hostapd/hostapd.conf

(2) Enter the following content, save and exit

Section titled “(2) Enter the following content, save and exit”
interface=wlan0
driver=nl80211
hw_mode=a
ieee80211n=1
ieee80211ac=1
ieee80211d=1
ieee80211h=1
require_ht=1
require_vht=1
wmm_enabled=1
country_code=US
vht_oper_chwidth=1
channel=149
vht_oper_centr_freq_seg0_idx=155
ht_capab=[HT40-][HT40+][SHORT-GI-40][DSSS_CCK-40]
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
ssid=PI_WIFI
wpa_passphrase=password
  • In layman’s terms, ssid is the network name of Wi-Fi.
  • wpa_passphrase is the Wi-Fi password
  • ssid and wpa_passphrase can be changed at will, but be careful that wpa_passphrase is more than 8 bytes
  • Generally speaking, there is no need to change the channel, because the frequency band available in China requires a continuous 80MHz bandwidth, and no matter how you adjust it, there is no way for two APs to have no overlapping frequency bands.
  • The country_code must be present and must be US. I have tried changing it to CN but it cannot be started.

(3) Write the configuration file path into the service configuration file

Section titled “(3) Write the configuration file path into the service configuration file”
echo "DAEMON_CONF=\"/etc/hostapd/hostapd.conf\"" >> /etc/default/hostapd
sudo systemctl start hostapd
sudo systemctl start dnsmasq
sudo vim /etc/rc.local

(2) Add the following content beforeExit 0, save and exit

Section titled “(2) Add the following content beforeExit 0, save and exit”
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
sudo /etc/rc.local

(1) Additional software installation is required

Section titled “(1) Additional software installation is required”
sudo apt-get install bridge-utils ebtables radvd -y

Edit the configuration file /etc/sysctl.conf and remove the comment from the following line net.ipv6.conf.all.forwarding=1

(3) Write the configuration file based on the globally unique IPv6 obtained by the actual network port

Section titled “(3) Write the configuration file based on the globally unique IPv6 obtained by the actual network port”

vim /etc/radvd.conf

interface wlan0
{
AdvSendAdvert on;
prefix 2001:da8:7001:251::/64
{
AdvOnLink on;
AdvAutonomous on;
AdvRouterAddr on;
};
};
  • 2001:da8:7001:251::/64is the IPv6 address corresponding toScope:Globalobtained throughifconfig

Edit /etc/rc.local

iptables -t nat -A POSTROUTING -s 10.0.0.0/8 -o ppp0 -j MASQUERADE
service radvd start
ebtables -t broute -A BROUTING -p ! ipv6 -j DROP
brctl addbr br0
ifconfig br0 up
brctl addif br0 eth0
brctl addif br0 wlan0
  • There is a compatibility issue here [ebtables], ebtables needs to be set Enterupdate-alternatives --set ebtables /usr/sbin/ebtables-legacyin the command line. The main problem is that the new version of ebtalbes is incompatible with the command and you need to switch to the old version of the program.

After turning on IPv6 transparent transmission, there are network problems, and the cause of the problem is unknown. The main phenomenon is that the docker network is completely down (maybe because of the host’s network settings, maybe using Bridge)

[1]. Ubuntu dependency resolution and installation [2]. Linux-A brief analysis of text processing commands [ebtables]:https://github.com/netblue30/firejail/issues/2232

Shell string interception


tags: - Shellcategories: - Linuxdate:created: 2020-09-11# updated: 2024-01-19—

Format illustrate
${string: start :length} Starting from the start character on the left side of the string string, intercept length to the right.
${string: start} Intercept from the start character on the left side of the string string until the end
${string: 0-start :length} Starting from the start character on the right side of the string string, intercept length to the right.
${string: 0-start} Intercept from the start character on the right side of the string string until the end
${string#*chars} Starting from the first occurrence of *chars in the string string, intercept *chars
${string##*chars} Starting from the last occurrence of *chars in the string string, intercept *chars
${string%*chars} Starting from the first occurrence of *chars in the string string, intercept *chars
${string%%*chars} Starting from the last occurrence of *chars in the string string, intercept *chars

[2]. Cloudflare-DDNS-with-ShellScripts [3]. Auto-Archive-Files-with-ShellScripts