版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 (http://blog.csdn.net/quqi99)

问题

今天在处理一个AppArmor的问题时,遇到一个奇怪的问题,在/etc/apparmor.d/usr.bin.nova-compute文件中明明已经有了下面对/tmp及/var/tmp目录的配置。

  /tmp/* rw,/tmp/*/ rw,/tmp/** rw,/var/tmp/* rw,

但是在运行”sudo /etc/init.d/apparmor reload && sudo service nova-compute restart“命令后仍然在syslog里能看到下列错误信息。奇了怪了,这是怎么一回事呢?

Nov 15 12:49:36 juju-864213-xenial-mitaka-ceph-11 kernel: [705198.766810] audit: type=1400 audit(1510750176.727:10140): apparmor="DENIED" operation="open" profile="/usr/bin/nova-compute" name="/tmp/" pid=16922 comm="nova-compute" requested_mask="r" denied_mask="r" fsuid=113 ouid=0
Nov 15 12:49:36 juju-864213-xenial-mitaka-ceph-11 kernel: [705198.766828] audit: type=1400 audit(1510750176.727:10141): apparmor="DENIED" operation="open" profile="/usr/bin/nova-compute" name="/var/tmp/" pid=16922 comm="nova-compute" requested_mask="r" denied_mask="r" fsuid=113 ouid=0

globstar模式下的通配符

通配符有一个星号,两个星号,还有逗号,globstar模式可以开启,还可以关闭。这些混在一起会有什么影响呢?
如果想要很方便地遍历所有的目录和文件得用两个星号的通配符。globstar是Bash 4.0才引入的选项,当设置启用globstar(shopt -s globstar)时,两个星号意为对通配符进行展开就可以匹配任何当前目录(包括子目录)以及其的文件;若不启用globstar(shopt -u globstar),两个星号通配符的作用和一个星号通配符是相同的。

  • ~/tmp/* - 匹配当前目录的文件,及当前目录的下一级目录(不包括当前目录),与’ls ~/tmp’及”ls ~/tmp/”的效果同。
  • ~/tmp/*/ - 匹配当前目录的下一级目录(不包括当前目录)
  • ~/tmp/* - 禁用globstar时,与~/tmp/完全一样(不包括当前目录);但启用globstar时,不止取一级,递归取所有级的文件和目录(也包括当前目录)
  • ~/tmp/*/ - 禁用globstar时,与~/tmp// 完全一样(不包括当前目录);但启用globstar时,不止取一级,递归取所有级的目录(也包括当前目录)

当启用globstar时,英语的解释如下(注:里面说的file包括文件和目录,在Linux里目录是特殊的文件):

Substitutes for any number of characters, except /.
/tmp/* matches any file in /tmp.
/tmp/*/ matches any directory in /tmpSubstitutes for any number of characters, including /.
/tmp/** matches all files and directories underneath /tmp.
/tmp/**/ matches all directories underneath /tmp.

请看实验数据:

hua@t440p:~/tmp$ tree .
.
├── l0_dir1
│   ├── l1_dir
│   │   ├── l2_dir
│   │   │   └── l3_file
│   │   └── l2_file
│   └── l1_file
├── l0_dir2
└── l0_file
4 directories, 4 fileshua@t440p:~/tmp$ shopt -s globstarhua@t440p:~/tmp$ ls ~/tmp/*
/home/hua/tmp/l0_file
/home/hua/tmp/l0_dir1:
l1_dir  l1_file
/home/hua/tmp/l0_dir2:hua@t440p:~/tmp$ ls ~/tmp/*/
/home/hua/tmp/l0_dir1/:
l1_dir  l1_file
/home/hua/tmp/l0_dir2/:hua@t440p:~/tmp$ ls ~/tmp/**
/home/hua/tmp/l0_dir1/l1_dir/l2_dir/l3_file  /home/hua/tmp/l0_dir1/l1_file
/home/hua/tmp/l0_dir1/l1_dir/l2_file         /home/hua/tmp/l0_file
/home/hua/tmp/:
l0_dir1  l0_dir2  l0_file
/home/hua/tmp/l0_dir1:
l1_dir  l1_file
/home/hua/tmp/l0_dir1/l1_dir:
l2_dir  l2_file
/home/hua/tmp/l0_dir1/l1_dir/l2_dir:
l3_file
/home/hua/tmp/l0_dir2:hua@t440p:~/tmp$ ls ~/tmp/**/
/home/hua/tmp/:
l0_dir1  l0_dir2  l0_file
/home/hua/tmp/l0_dir1/:
l1_dir  l1_file
/home/hua/tmp/l0_dir1/l1_dir/:
l2_dir  l2_file
/home/hua/tmp/l0_dir1/l1_dir/l2_dir/:
l3_file
/home/hua/tmp/l0_dir2/:hua@t440p:~/tmp$ ls ~/tmp/{,**}
/home/hua/tmp/l0_file
/home/hua/tmp/:
l0_dir1  l0_dir2  l0_file
/home/hua/tmp/l0_dir1:
l1_dir  l1_file
/home/hua/tmp/l0_dir2:hua@t440p:~/tmp$ shopt -u globstarhua@t440p:~/tmp$ ls ~/tmp/*
/home/hua/tmp/l0_file
/home/hua/tmp/l0_dir1:
l1_dir  l1_file
/home/hua/tmp/l0_dir2:hua@t440p:~/tmp$ ls ~/tmp/*/
/home/hua/tmp/l0_dir1/:
l1_dir  l1_file
/home/hua/tmp/l0_dir2/:hua@t440p:~/tmp$ ls ~/tmp/**
/home/hua/tmp/l0_file
/home/hua/tmp/l0_dir1:
l1_dir  l1_file
/home/hua/tmp/l0_dir2:hua@t440p:~/tmp$ ls ~/tmp/**/
/home/hua/tmp/l0_dir1/:
l1_dir  l1_file
/home/hua/tmp/l0_dir2/:hua@t440p:~/tmp$ ls ~/tmp/{,**}
/home/hua/tmp/l0_file
/home/hua/tmp/:
l0_dir1  l0_dir2  l0_file
/home/hua/tmp/l0_dir1:
l1_dir  l1_file
/home/hua/tmp/l0_dir2:

问题的解决

学习了上面的理论之后,是不是想到了问题所在了,那就是下列两个配置没有包括当前目录:

  /tmp/** rw,/var/tmp/* rw,

所以它应该修改为:

/tmp/{,**} rw,
/var/tmp/{,**} rw,

附录 - appamor attach disconnected

echo ‘show stat;show table’ | socat stdio /var/lib/neutron/lbaas/v2/xxx/haproxy_stats.sock
上面命令出问题时,可能需要在appamor中添加apparmor flags=(attach disconnected),见:https://bugs.launchpad.net/charm-neutron-gateway/+bug/1770040/comments/10

通配符中一个星号两个星号和globstar的关系(by quqi99)相关推荐

  1. python 函数参数前面两个星号_Python中参数前面一个星号两个星号(*参数,**参数)起什么作用呢?...

    摘要: 下文讲述Python中参数前面一个星号两个星号的功能分享,如下所示: 在Python语言中,我们经常看见参数前面 加上一个星号或两个星号 那么这些写法到底起什么作用呢? 下文将一一道来,如下所 ...

  2. python中的星号和乘号_Python 函数中参数前面一个和两个星号(**)的区别

    Python是一种计算机程序设计语言.是一种面向对象的动态类型语言,最初被设计用于编写自动化 脚本( shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大型项目的开发. 在 P ...

  3. 技术沙龙系列之:Python 函数参数前面一个星号(*)和两个星号(**)的区别

    下面来谈谈Python 函数参数前面一个星号(*)和两个星号(**)的区别,这也是许多小伙伴在学习时的一个困惑,简单为大家介绍一下: 在 Python 的函数中经常能看到输入的参数前面有一个或者两个星 ...

  4. python中一个星号(*)与两个星号(**)的作用

    python中一个星号(*)与两个星号(**)的作用 目录 python中一个星号(`*`)与两个星号(`**`)的作用 一.一般用法 概述: 1.`*`表示乘法,`**`表示幂 2.`*`表示打包解 ...

  5. python中syntaxerror_【已解决】Python中两个星号**参数去传递给函数出错:SyntaxError invalid syntax...

    python 3.4中,代码:print("type(self.config)=%s" % (type(self.config))) self.connection = pymys ...

  6. 一个星号的指针和两个星号的有什么区别

    typedef struct jilu {     char *value;     struct jilu *next; }JL; JL * head = NULL; JL ** p, *q; // ...

  7. Python函数参数前面一个星号(*)和两个星号(**)的含义

    这两种用法其实都是用来将任意个数的参数导入到 Python 函数中.这两个用法可以同时出现在一个函数中. 单星号(*):*agrs.将所有参数以元组(tuple)的形式导入 双星号(**):**kwa ...

  8. python双等号怎么输入_python中的星号‘*’和双星号‘**’的解说

    一直以来,对于python中函数参数传递过程中出现的*和**,理解的稀里糊涂的.最近看了一篇博文,描述的非常清楚,所以自己也抽空写了一下,可以整理一下自己的思路,也可以帮助到像我一样的白白小学生. p ...

  9. python函数的动态参数之一个星号和两个星号

    一.概述 1.python有位置参数.默认参数,这两种是最常用的参数. 2.动态参数即不限定参数个数,以一种动态的方式接受传参的个数. 3.python的动态参数有两种,分别是 ' *args '  ...

最新文章

  1. NTU课程笔记 MAS714(2) Big-O notations
  2. boost::math模块使用正态分布的示例
  3. Android电池电量更新 - BatteryService(转)
  4. [蓝桥杯][2019年第十届真题]后缀表达式(正解!!)
  5. VMware下主机与虚拟机剪切板独立,无法直接复制粘贴
  6. explode php 正则,php用preg_replace和explode将li列表分割成纯文本数组
  7. shiro中ini配置文件
  8. python基础学习-字符串
  9. MEncoder的基础用法—6.7. 媒体流复制
  10. FZCCHJW--GB1-0-GBpc-EUC-H:在系统中未找到字体;已替换缺少的字体。
  11. 【Android常识】Android之父Andy Rubin:被乔布斯羡慕嫉妒的天才
  12. Q1月活大涨70%,后浪会成B站的流量萌新吗?
  13. 微信小程序 重新刷新页面
  14. 伦敦经济学院开设加密货币相关课程
  15. CGAL的安装与在VS中的配置
  16. 【历史上的今天】2 月 18 日:电池的发明者出生;全美最大的电脑连锁店开业;Netsky 蠕虫问世
  17. 蚂蚁金服 ant design 中下载axure 菜单组件库
  18. 昱章电气在科创板IPO终止:曾计划募资约5亿元,客户集中度较高
  19. Impala 技术点梳理
  20. 阿里巴巴云游戏(元境)春季2023届校园招聘正式开启

热门文章

  1. 如何进行有效的性能测试
  2. 在电脑上写日记怎么加密
  3. 光纤弯曲半径不足对ODN链路衰耗的影响
  4. windows快速关机
  5. R语言绘制图例(legend)的各种问题_详细综合解析
  6. 万头攒动火树银花之处不必找我。如欲相见,我在各种悲喜交集处,能做的只是长途跋涉的归真返璞。
  7. yiwoSDK QQ通讯协议的封装 快速做出QQ推广产品
  8. 京鱼座智能屏i8 Pro“强势出道”,重新思考智能音箱的产业坐标系
  9. 网页在图片上画长方形和直线,并且能控制和编辑
  10. RIME中州韵输入法引擎学习