Debugging policies

When working on more complex queries (or when learning Rego), it’s useful to see exactly how the policy is applied. For this purpose you can use the --trace flag. This will output a large trace from Open Policy Agent like the following:

Tip

Only failed policies show traces. If you want to debug a passed policy, you need to make it fail on purpose.

  1. $ trivy conf --trace configs/
  2. 2021-07-11T16:45:58.493+0300 INFO Detected config files: 1
  3. Dockerfile (dockerfile)
  4. =======================
  5. Tests: 23 (SUCCESSES: 22, FAILURES: 1, EXCEPTIONS: 0)
  6. Failures: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 1, CRITICAL: 0)
  7. +---------------------------+------------+----------------------+----------+------------------------------------------+
  8. | TYPE | MISCONF ID | CHECK | SEVERITY | MESSAGE |
  9. +---------------------------+------------+----------------------+----------+------------------------------------------+
  10. | Dockerfile Security Check | DS002 | Image user is 'root' | HIGH | Last USER command in |
  11. | | | | | Dockerfile should not be 'root' |
  12. | | | | | -->avd.aquasec.com/appshield/ds002 |
  13. +---------------------------+------------+----------------------+----------+------------------------------------------+
  14. ID: DS002
  15. File: Dockerfile
  16. Namespace: appshield.dockerfile.DS002
  17. Query: data.appshield.dockerfile.DS002.deny
  18. Message: Last USER command in Dockerfile should not be 'root'
  19. TRACE Enter data.appshield.dockerfile.DS002.deny = _
  20. TRACE | Eval data.appshield.dockerfile.DS002.deny = _
  21. TRACE | Index data.appshield.dockerfile.DS002.deny matched 2 rules)
  22. TRACE | Enter data.appshield.dockerfile.DS002.deny
  23. TRACE | | Eval data.appshield.dockerfile.DS002.fail_user_count
  24. TRACE | | Index data.appshield.dockerfile.DS002.fail_user_count (matched 1 rule)
  25. TRACE | | Enter data.appshield.dockerfile.DS002.fail_user_count
  26. TRACE | | | Eval __local559__ = data.appshield.dockerfile.DS002.get_user
  27. TRACE | | | Index data.appshield.dockerfile.DS002.get_user (matched 1 rule)
  28. TRACE | | | Enter data.appshield.dockerfile.DS002.get_user
  29. TRACE | | | | Eval user = data.lib.docker.user[_]
  30. TRACE | | | | Index data.lib.docker.user (matched 1 rule)
  31. TRACE | | | | Enter data.lib.docker.user
  32. TRACE | | | | | Eval instruction = input.stages[_][_]
  33. TRACE | | | | | Eval instruction.Cmd = "user"
  34. TRACE | | | | | Fail instruction.Cmd = "user"
  35. TRACE | | | | | Redo instruction = input.stages[_][_]
  36. TRACE | | | | | Eval instruction.Cmd = "user"
  37. TRACE | | | | | Fail instruction.Cmd = "user"
  38. TRACE | | | | | Redo instruction = input.stages[_][_]
  39. TRACE | | | | | Eval instruction.Cmd = "user"
  40. TRACE | | | | | Fail instruction.Cmd = "user"
  41. TRACE | | | | | Redo instruction = input.stages[_][_]
  42. TRACE | | | | | Eval instruction.Cmd = "user"
  43. TRACE | | | | | Fail instruction.Cmd = "user"
  44. TRACE | | | | | Redo instruction = input.stages[_][_]
  45. TRACE | | | | | Eval instruction.Cmd = "user"
  46. TRACE | | | | | Fail instruction.Cmd = "user"
  47. TRACE | | | | | Redo instruction = input.stages[_][_]
  48. TRACE | | | | | Eval instruction.Cmd = "user"
  49. TRACE | | | | | Fail instruction.Cmd = "user"
  50. TRACE | | | | | Redo instruction = input.stages[_][_]
  51. TRACE | | | | | Eval instruction.Cmd = "user"
  52. TRACE | | | | | Fail instruction.Cmd = "user"
  53. TRACE | | | | | Redo instruction = input.stages[_][_]
  54. TRACE | | | | | Eval instruction.Cmd = "user"
  55. TRACE | | | | | Exit data.lib.docker.user
  56. TRACE | | | | Eval username = user.Value[_]
  57. TRACE | | | | Exit data.appshield.dockerfile.DS002.get_user
  58. TRACE | | | Redo data.appshield.dockerfile.DS002.get_user
  59. TRACE | | | | Redo username = user.Value[_]
  60. TRACE | | | | Redo user = data.lib.docker.user[_]
  61. TRACE | | | | Redo data.lib.docker.user
  62. TRACE | | | | | Redo instruction.Cmd = "user"
  63. TRACE | | | | | Redo instruction = input.stages[_][_]
  64. TRACE | | | | | Eval instruction.Cmd = "user"
  65. TRACE | | | | | Exit data.lib.docker.user
  66. TRACE | | | | Eval username = user.Value[_]
  67. TRACE | | | | Exit data.appshield.dockerfile.DS002.get_user
  68. TRACE | | | Redo data.appshield.dockerfile.DS002.get_user
  69. TRACE | | | | Redo username = user.Value[_]
  70. TRACE | | | | Redo user = data.lib.docker.user[_]
  71. TRACE | | | | Redo data.lib.docker.user
  72. TRACE | | | | | Redo instruction.Cmd = "user"
  73. TRACE | | | | | Redo instruction = input.stages[_][_]
  74. TRACE | | | | | Eval instruction.Cmd = "user"
  75. TRACE | | | | | Fail instruction.Cmd = "user"
  76. TRACE | | | | | Redo instruction = input.stages[_][_]
  77. TRACE | | | Eval count(__local559__, __local391__)
  78. TRACE | | | Eval lt(__local391__, 1)
  79. TRACE | | | Fail lt(__local391__, 1)
  80. TRACE | | | Redo count(__local559__, __local391__)
  81. TRACE | | | Redo __local559__ = data.appshield.dockerfile.DS002.get_user
  82. TRACE | | Fail data.appshield.dockerfile.DS002.fail_user_count
  83. TRACE | Enter data.appshield.dockerfile.DS002.deny
  84. TRACE | | Eval data.appshield.dockerfile.DS002.fail_last_user_root
  85. TRACE | | Index data.appshield.dockerfile.DS002.fail_last_user_root (matched 1 rule)
  86. TRACE | | Enter data.appshield.dockerfile.DS002.fail_last_user_root
  87. TRACE | | | Eval __local560__ = data.appshield.dockerfile.DS002.get_user
  88. TRACE | | | Index data.appshield.dockerfile.DS002.get_user (matched 1 rule)
  89. TRACE | | | Enter data.appshield.dockerfile.DS002.get_user
  90. TRACE | | | | Eval user = data.lib.docker.user[_]
  91. TRACE | | | | Index data.lib.docker.user (matched 1 rule)
  92. TRACE | | | | Enter data.lib.docker.user
  93. TRACE | | | | | Eval instruction = input.stages[_][_]
  94. TRACE | | | | | Eval instruction.Cmd = "user"
  95. TRACE | | | | | Fail instruction.Cmd = "user"
  96. TRACE | | | | | Redo instruction = input.stages[_][_]
  97. TRACE | | | | | Eval instruction.Cmd = "user"
  98. TRACE | | | | | Fail instruction.Cmd = "user"
  99. TRACE | | | | | Redo instruction = input.stages[_][_]
  100. TRACE | | | | | Eval instruction.Cmd = "user"
  101. TRACE | | | | | Fail instruction.Cmd = "user"
  102. TRACE | | | | | Redo instruction = input.stages[_][_]
  103. TRACE | | | | | Eval instruction.Cmd = "user"
  104. TRACE | | | | | Fail instruction.Cmd = "user"
  105. TRACE | | | | | Redo instruction = input.stages[_][_]
  106. TRACE | | | | | Eval instruction.Cmd = "user"
  107. TRACE | | | | | Fail instruction.Cmd = "user"
  108. TRACE | | | | | Redo instruction = input.stages[_][_]
  109. TRACE | | | | | Eval instruction.Cmd = "user"
  110. TRACE | | | | | Fail instruction.Cmd = "user"
  111. TRACE | | | | | Redo instruction = input.stages[_][_]
  112. TRACE | | | | | Eval instruction.Cmd = "user"
  113. TRACE | | | | | Fail instruction.Cmd = "user"
  114. TRACE | | | | | Redo instruction = input.stages[_][_]
  115. TRACE | | | | | Eval instruction.Cmd = "user"
  116. TRACE | | | | | Exit data.lib.docker.user
  117. TRACE | | | | Eval username = user.Value[_]
  118. TRACE | | | | Exit data.appshield.dockerfile.DS002.get_user
  119. TRACE | | | Redo data.appshield.dockerfile.DS002.get_user
  120. TRACE | | | | Redo username = user.Value[_]
  121. TRACE | | | | Redo user = data.lib.docker.user[_]
  122. TRACE | | | | Redo data.lib.docker.user
  123. TRACE | | | | | Redo instruction.Cmd = "user"
  124. TRACE | | | | | Redo instruction = input.stages[_][_]
  125. TRACE | | | | | Eval instruction.Cmd = "user"
  126. TRACE | | | | | Exit data.lib.docker.user
  127. TRACE | | | | Eval username = user.Value[_]
  128. TRACE | | | | Exit data.appshield.dockerfile.DS002.get_user
  129. TRACE | | | Redo data.appshield.dockerfile.DS002.get_user
  130. TRACE | | | | Redo username = user.Value[_]
  131. TRACE | | | | Redo user = data.lib.docker.user[_]
  132. TRACE | | | | Redo data.lib.docker.user
  133. TRACE | | | | | Redo instruction.Cmd = "user"
  134. TRACE | | | | | Redo instruction = input.stages[_][_]
  135. TRACE | | | | | Eval instruction.Cmd = "user"
  136. TRACE | | | | | Fail instruction.Cmd = "user"
  137. TRACE | | | | | Redo instruction = input.stages[_][_]
  138. TRACE | | | Eval cast_array(__local560__, __local392__)
  139. TRACE | | | Eval user = __local392__
  140. TRACE | | | Eval __local561__ = data.appshield.dockerfile.DS002.get_user
  141. TRACE | | | Index data.appshield.dockerfile.DS002.get_user (matched 1 rule)
  142. TRACE | | | Enter data.appshield.dockerfile.DS002.get_user
  143. TRACE | | | | Eval user = data.lib.docker.user[_]
  144. TRACE | | | | Index data.lib.docker.user (matched 1 rule)
  145. TRACE | | | | Enter data.lib.docker.user
  146. TRACE | | | | | Eval instruction = input.stages[_][_]
  147. TRACE | | | | | Eval instruction.Cmd = "user"
  148. TRACE | | | | | Fail instruction.Cmd = "user"
  149. TRACE | | | | | Redo instruction = input.stages[_][_]
  150. TRACE | | | | | Eval instruction.Cmd = "user"
  151. TRACE | | | | | Fail instruction.Cmd = "user"
  152. TRACE | | | | | Redo instruction = input.stages[_][_]
  153. TRACE | | | | | Eval instruction.Cmd = "user"
  154. TRACE | | | | | Fail instruction.Cmd = "user"
  155. TRACE | | | | | Redo instruction = input.stages[_][_]
  156. TRACE | | | | | Eval instruction.Cmd = "user"
  157. TRACE | | | | | Fail instruction.Cmd = "user"
  158. TRACE | | | | | Redo instruction = input.stages[_][_]
  159. TRACE | | | | | Eval instruction.Cmd = "user"
  160. TRACE | | | | | Fail instruction.Cmd = "user"
  161. TRACE | | | | | Redo instruction = input.stages[_][_]
  162. TRACE | | | | | Eval instruction.Cmd = "user"
  163. TRACE | | | | | Fail instruction.Cmd = "user"
  164. TRACE | | | | | Redo instruction = input.stages[_][_]
  165. TRACE | | | | | Eval instruction.Cmd = "user"
  166. TRACE | | | | | Fail instruction.Cmd = "user"
  167. TRACE | | | | | Redo instruction = input.stages[_][_]
  168. TRACE | | | | | Eval instruction.Cmd = "user"
  169. TRACE | | | | | Exit data.lib.docker.user
  170. TRACE | | | | Eval username = user.Value[_]
  171. TRACE | | | | Exit data.appshield.dockerfile.DS002.get_user
  172. TRACE | | | Redo data.appshield.dockerfile.DS002.get_user
  173. TRACE | | | | Redo username = user.Value[_]
  174. TRACE | | | | Redo user = data.lib.docker.user[_]
  175. TRACE | | | | Redo data.lib.docker.user
  176. TRACE | | | | | Redo instruction.Cmd = "user"
  177. TRACE | | | | | Redo instruction = input.stages[_][_]
  178. TRACE | | | | | Eval instruction.Cmd = "user"
  179. TRACE | | | | | Exit data.lib.docker.user
  180. TRACE | | | | Eval username = user.Value[_]
  181. TRACE | | | | Exit data.appshield.dockerfile.DS002.get_user
  182. TRACE | | | Redo data.appshield.dockerfile.DS002.get_user
  183. TRACE | | | | Redo username = user.Value[_]
  184. TRACE | | | | Redo user = data.lib.docker.user[_]
  185. TRACE | | | | Redo data.lib.docker.user
  186. TRACE | | | | | Redo instruction.Cmd = "user"
  187. TRACE | | | | | Redo instruction = input.stages[_][_]
  188. TRACE | | | | | Eval instruction.Cmd = "user"
  189. TRACE | | | | | Fail instruction.Cmd = "user"
  190. TRACE | | | | | Redo instruction = input.stages[_][_]
  191. TRACE | | | Eval count(__local561__, __local393__)
  192. TRACE | | | Eval len = __local393__
  193. TRACE | | | Eval minus(len, 1, __local394__)
  194. TRACE | | | Eval user[__local394__] = "root"
  195. TRACE | | | Exit data.appshield.dockerfile.DS002.fail_last_user_root
  196. TRACE | | Eval res = "Last USER command in Dockerfile should not be 'root'"
  197. TRACE | | Exit data.appshield.dockerfile.DS002.deny
  198. TRACE | Redo data.appshield.dockerfile.DS002.deny
  199. TRACE | | Redo res = "Last USER command in Dockerfile should not be 'root'"
  200. TRACE | | Redo data.appshield.dockerfile.DS002.fail_last_user_root
  201. TRACE | | Redo data.appshield.dockerfile.DS002.fail_last_user_root
  202. TRACE | | | Redo user[__local394__] = "root"
  203. TRACE | | | Redo minus(len, 1, __local394__)
  204. TRACE | | | Redo len = __local393__
  205. TRACE | | | Redo count(__local561__, __local393__)
  206. TRACE | | | Redo __local561__ = data.appshield.dockerfile.DS002.get_user
  207. TRACE | | | Redo user = __local392__
  208. TRACE | | | Redo cast_array(__local560__, __local392__)
  209. TRACE | | | Redo __local560__ = data.appshield.dockerfile.DS002.get_user
  210. TRACE | Exit data.appshield.dockerfile.DS002.deny = _
  211. TRACE Redo data.appshield.dockerfile.DS002.deny = _
  212. TRACE | Redo data.appshield.dockerfile.DS002.deny = _