Skip to content

Let command plugins ask for network permissions#6114

Merged
neonichu merged 1 commit into
mainfrom
command-plugin-network-permissions
Feb 8, 2023
Merged

Let command plugins ask for network permissions#6114
neonichu merged 1 commit into
mainfrom
command-plugin-network-permissions

Conversation

@neonichu

@neonichu neonichu commented Feb 3, 2023

Copy link
Copy Markdown
Contributor

This adds a new plugin permission that allows a command plugin to ask for networking permissions. The permission can distinguish between local and outgoing connections, as well as specifying a list or range of ports to allow. Similar to existing permissions, there's also a CLI option for allowing connections.

resolves #5489

@neonichu neonichu self-assigned this Feb 3, 2023
@neonichu

neonichu commented Feb 3, 2023

Copy link
Copy Markdown
Contributor Author

@swift-ci please smoke test

@neonichu neonichu force-pushed the command-plugin-network-permissions branch 2 times, most recently from 54ccb20 to 736e565 Compare February 3, 2023 20:43
@neonichu neonichu changed the title WIP: Let command plugins ask for network permissions Let command plugins ask for network permissions Feb 3, 2023
@neonichu neonichu marked this pull request as ready for review February 3, 2023 20:44
@neonichu

neonichu commented Feb 3, 2023

Copy link
Copy Markdown
Contributor Author

@swift-ci please smoke test

let answer = readLine(strippingNewline: true)
// Throw an error if we didn't get permission.
if answer?.lowercased() != "yes" {
throw StringError("Plugin was denied permission to \(permissionString).")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I changed these to StringError to avoid having usage be printed to the console which seems to be a behavior of ArgumentParser's ValidationError.

Comment thread Sources/Workspace/DefaultPluginScriptRunner.swift Outdated
Comment thread Sources/PackageDescription/Target.swift

@tomerd tomerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great. consider adding a few more tests for different manifest usage patterns

@neonichu neonichu force-pushed the command-plugin-network-permissions branch from 736e565 to ce08da5 Compare February 3, 2023 22:48
@neonichu

neonichu commented Feb 3, 2023

Copy link
Copy Markdown
Contributor Author

@swift-ci please smoke test

@neonichu neonichu force-pushed the command-plugin-network-permissions branch from ce08da5 to ac28899 Compare February 4, 2023 00:23
@neonichu

neonichu commented Feb 4, 2023

Copy link
Copy Markdown
Contributor Author

@swift-ci please smoke test

@neonichu neonichu force-pushed the command-plugin-network-permissions branch from ac28899 to dcf0a19 Compare February 4, 2023 00:56
@neonichu

neonichu commented Feb 4, 2023

Copy link
Copy Markdown
Contributor Author

@swift-ci please smoke test

Comment thread Sources/Commands/PackageTools/PluginCommand.swift Outdated
accessibleTools: accessibleTools,
writableDirectories: writableDirectories,
readOnlyDirectories: readOnlyDirectories,
allowNetworkConnections: [],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow why this is empty in this call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the invocation for build tools which do not support specifying permissions.

Comment thread Sources/Workspace/DefaultPluginScriptRunner.swift Outdated
Comment thread Tests/CommandsTests/PackageToolTests.swift
@tomerd

tomerd commented Feb 4, 2023

Copy link
Copy Markdown
Contributor

cc @fabianfett

Comment thread Documentation/Plugins.md Outdated
This adds a new plugin permission that allows a command plugin to ask for networking permissions. The permission can distinguish between local and outgoing connections, as well as specifying a list or range of ports to allow. Similar to existing permissions, there's also a CLI option for allowing connections.

resolves #5489
@neonichu neonichu force-pushed the command-plugin-network-permissions branch from 32a44a3 to 83d7b3d Compare February 6, 2023 17:10
@neonichu

neonichu commented Feb 6, 2023

Copy link
Copy Markdown
Contributor Author

@swift-ci please smoke test

1 similar comment
@neonichu

neonichu commented Feb 6, 2023

Copy link
Copy Markdown
Contributor Author

@swift-ci please smoke test

@neonichu

neonichu commented Feb 6, 2023

Copy link
Copy Markdown
Contributor Author

Windows failure looks like something in llbuild? cc @compnerd

[143/150][ 95%][23.201s] Linking CXX executable bin\CAPITests.exe
FAILED: bin/CAPITests.exe 
cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=unittests\CAPI\CMakeFiles\CAPITests.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\mt.exe --manifests  -- T:\1\bin\lld-link.exe /nologo unittests\CAPI\CMakeFiles\CAPITests.dir\C-API.cpp.obj unittests\CAPI\CMakeFiles\CAPITests.dir\BuildSystem-C-API.cpp.obj  /out:bin\CAPITests.exe /implib:lib\CAPITests.lib /pdb:bin\CAPITests.pdb /version:0.0 /INCREMENTAL:NO /INCREMENTAL:NO /subsystem:console  lib\gtest.lib  lib\gtest_main.lib  lib\llvmSupport.lib  lib\llbuildBasic.lib  lib\llbuild.lib  T:\Library\sqlite-3.36.0\usr\lib\SQLite3.lib  lib\gtest.lib  lib\llvmSupport.lib  lib\LLVMDemangle.lib  ShLwApi.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "T:\1\bin\lld-link.exe /nologo unittests\CAPI\CMakeFiles\CAPITests.dir\C-API.cpp.obj unittests\CAPI\CMakeFiles\CAPITests.dir\BuildSystem-C-API.cpp.obj /out:bin\CAPITests.exe /implib:lib\CAPITests.lib /pdb:bin\CAPITests.pdb /version:0.0 /INCREMENTAL:NO /INCREMENTAL:NO /subsystem:console lib\gtest.lib lib\gtest_main.lib lib\llvmSupport.lib lib\llbuildBasic.lib lib\llbuild.lib T:\Library\sqlite-3.36.0\usr\lib\SQLite3.lib lib\gtest.lib lib\llvmSupport.lib lib\LLVMDemangle.lib ShLwApi.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:bin\CAPITests.exe.manifest" failed (exit code 1) with the following output:
lld-link: error: undefined symbol: llb_get_api_version
>>> referenced by unittests\CAPI\CMakeFiles\CAPITests.dir\C-API.cpp.obj:(private: virtual void __cdecl `anonymous namespace'::CAPI_GetAPIVersion_Test::TestBody(void))

@compnerd

compnerd commented Feb 6, 2023

Copy link
Copy Markdown
Member

Please test with following PRs:
swiftlang/swift-llbuild#860

@swift-ci please test Windows platform

@neonichu

neonichu commented Feb 7, 2023

Copy link
Copy Markdown
Contributor Author

@swift-ci please test Windows platform

@neonichu

neonichu commented Feb 7, 2023

Copy link
Copy Markdown
Contributor Author

Seems like update_checkout is broken on Windows right now cc @shahmishal @compnerd

[llvm-project]                          Updating 'C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\llvm-project'
Error on repo "C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\llvm-project": Traceback (most recent call last):
  File "C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift\utils\update_checkout\update_checkout\update_checkout.py", line 201, in update_single_repository
    shell.run(['git', 'rev-parse', '--verify', checkout_target])
  File "C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift\utils\swift_build_support\swift_build_support\shell.py", line 255, in run
    raise eout
Exception: ['git', 'rev-parse', '--verify', 'stable/20220421']

There are also more follow-on errors.

@neonichu

neonichu commented Feb 8, 2023

Copy link
Copy Markdown
Contributor Author

Hm, I guess the Windows CI re-run itself, confusing...

@shahmishal

Copy link
Copy Markdown
Member

Hm, I guess the Windows CI re-run itself, confusing...

I did it from the backend, sorry I should have told you about it.

Comment thread Documentation/Plugins.md
```

Command plugins that need to write to the file system will cause SwiftPM to ask the user for approval if `swift package` is invoked from a console, or deny the request if it is not. Passing the `--allow-writing-to-package-directory` flag to the `swift package` invocation will allow the request without questions — this is particularly useful in a Continuous Integration environment.
Command plugins that need to write to the file system will cause SwiftPM to ask the user for approval if `swift package` is invoked from a console, or deny the request if it is not. Passing the `--allow-writing-to-package-directory` flag to the `swift package` invocation will allow the request without questions — this is particularly useful in a Continuous Integration environment. Similarly, the `--allow-network-connections` flag can be used to allow network connections without showing a prompt.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this change also be mentioned in the changelog?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 this is a great feature we should mention in chnagelog and release notes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in #6132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow plugins to communicate with docker without disabling the sandbox

6 participants