hadolint 2.15.0 → 2.15.1
raw patch · 3 files changed
+39/−4 lines, 3 files
Files
- hadolint.cabal +3/−1
- src/Hadolint/Rule/DL3066.hs +31/−3
- test/Hadolint/Rule/DL3066Spec.hs +5/−0
hadolint.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.0 name: hadolint-version: 2.15.0+version: 2.15.1 synopsis: Dockerfile Linter JavaScript API description: A smarter Dockerfile linter that helps you build best practice Docker images.@@ -14,6 +14,8 @@ license-file: LICENSE build-type: Simple extra-source-files: README.md++tested-with: GHC == 9.10.3 source-repository head type: git
src/Hadolint/Rule/DL3066.hs view
@@ -1,19 +1,31 @@ module Hadolint.Rule.DL3066 (rule) where import qualified Data.Char as Char+import qualified Data.Set as Set import qualified Data.Text as Text import Hadolint.Rule import Language.Docker.Syntax ++data Acc+ = Acc { args :: Set.Set Text.Text }+ | Empty+ deriving (Show)++ rule :: Rule args-rule = simpleRule code severity message check+rule = customRule check (emptyState Empty) where code = "DL3066" severity = DLInfoC message = "Non-numeric user-id may not be resolvable by host system" - check (User u) = Text.all Char.isDigit $ getUid u- check _ = True+ check line st (User u)+ | Text.all Char.isDigit $ getUid u = st+ | uidIsDefinedArg (state st) u = st+ | otherwise = st |> addFail CheckFailure {..}+ check _ st (Arg arg _) = st |> modify (registerArg arg)+ check _ st _ = st {-# INLINEABLE rule #-} getUid :: Text.Text -> Text.Text@@ -23,3 +35,19 @@ where u [] = "" u (h:_) = h++uidIsDefinedArg :: Acc -> Text.Text -> Bool+uidIsDefinedArg Empty _ = False+uidIsDefinedArg (Acc args) u = any (`varInUid` u) args+ where+ varInUid :: Text.Text -> Text.Text -> Bool+ varInUid var uid =+ ( Text.pack "${" <> var <> Text.pack "}" ) `Text.isInfixOf` uid+ || ( Text.pack "$" <> var ) `Text.isInfixOf` uid++registerArg :: Text.Text -> Acc -> Acc+registerArg arg Empty =+ Acc { args = Set.singleton arg }+registerArg arg (Acc args) =+ Acc { args = Set.insert arg args }+
test/Hadolint/Rule/DL3066Spec.hs view
@@ -1,6 +1,7 @@ module Hadolint.Rule.DL3066Spec (spec) where import Data.Default+import qualified Data.Text as Text import Helpers import Test.Hspec @@ -23,3 +24,7 @@ it "not ok: non-numeric UID and GID" $ do ruleCatches rule "USER foobar:barfoo"++ it "ok: UID is non-numeric, but is a defined ARG" $ do+ let dockerfile = Text.unlines [ "ARG APP_UID", "FROM foobar:barfoo", "USER ${APP_UID}" ]+ in ruleCatchesNot rule dockerfile