Skip to content

Commit 85aa60b

Browse files
committed
pathrs-lite: move new API to subpackage
This code should probably have been in a subpackage from the start (since it has very little to do with securejoin) but at the time it felt like a very minimal workaround. Now that it looks like this is going to be a more permanent solution for part of the Go ecosystem (and the license for most of this code has been changed) we should separate it. The name "pathrs-lite" indicates what the purpose of this subpackage is (i.e., it is a less complete version of libpathrs). Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 6d90b55 commit 85aa60b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+214
-65
lines changed

CHANGELOG.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
## [Unreleased] ##
88

99
> **NOTE**: With this release, some parts of
10-
> `github.com/cyphar/filepath-securejoin` (notably the new APIs introduced
11-
> since the [0.3.0][] release) are now licensed under the Mozilla Public
12-
> License (version 2).
10+
> `github.com/cyphar/filepath-securejoin` are now licensed under the Mozilla
11+
> Public License (version 2). Please see [COPYING.md][] as well as the the
12+
> license header in each file for more details.
13+
14+
[COPYING.md]: ./COPYING.md
15+
16+
### Breaking ###
17+
- The new API introduced in the [0.3.0][] release has been moved to a new
18+
subpackage called `pathrs-lite`. This was primarily done to better indicate
19+
the split between the new and old APIs, as well as indicate to users the
20+
purpose of this subpackage (it is a less complete version of [libpathrs][]).
21+
22+
We have added some wrappers to the top-level package to ease the transition,
23+
but those are deprecated and will be removed in the next minor release of
24+
filepath-securejoin. Users should update their import paths.
1325

1426
### Added ###
15-
- Most of the key bits the safe `procfs` API have now been exposed. At the
16-
moment this primarily consists of a new `ProcfsHandle` API:
27+
- Most of the key bits the safe `procfs` API have now been exported and are
28+
available in `github.com/cyphar/filepath-securejoin/pathrs-lite/procfs`. At
29+
the moment this primarily consists of a new `procfs.Handle` API:
1730

1831
* `OpenProcRoot` returns a new handle to `/proc`, endeavouring to make it
1932
safe if possible (`subset=pid` to protect against mistaken write attacks
@@ -25,8 +38,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2538
of an operation, as filepath-securejoin will internally open a handle when
2639
necessary).
2740

28-
* The `(*ProcfsHandle).Open*` family of methods lets you get a safe `O_PATH`
29-
handle to subpaths within `/proc` for certain subpaths.
41+
* The `(*procfs.Handle).Open*` family of methods lets you get a safe
42+
`O_PATH` handle to subpaths within `/proc` for certain subpaths.
3043

3144
For `OpenThreadSelf`, the returned `ProcThreadSelfCloser` needs to be
3245
called after you completely finish using the handle (this is necessary

deprecated_linux.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
3+
//go:build linux
4+
5+
// Copyright (C) 2024-2025 Aleksa Sarai <[email protected]>
6+
// Copyright (C) 2024-2025 SUSE LLC
7+
//
8+
// This Source Code Form is subject to the terms of the Mozilla Public
9+
// License, v. 2.0. If a copy of the MPL was not distributed with this
10+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
11+
12+
package securejoin
13+
14+
import (
15+
"github.com/cyphar/filepath-securejoin/pathrs-lite"
16+
)
17+
18+
var (
19+
// MkdirAll is a wrapper around [pathrs.MkdirAll].
20+
//
21+
// Deprecated: You should use [pathrs.MkdirAll] directly instead. This
22+
// wrapper will be removed in filepath-securejoin v0.6.
23+
MkdirAll = pathrs.MkdirAll
24+
25+
// MkdirAllHandle is a wrapper around [pathrs.MkdirAllHandle].
26+
//
27+
// Deprecated: You should use [pathrs.MkdirAllHandle] directly instead.
28+
// This wrapper will be removed in filepath-securejoin v0.6.
29+
MkdirAllHandle = pathrs.MkdirAllHandle
30+
31+
// OpenInRoot is a wrapper around [pathrs.OpenInRoot].
32+
//
33+
// Deprecated: You should use [pathrs.OpenInRoot] directly instead. This
34+
// wrapper will be removed in filepath-securejoin v0.6.
35+
OpenInRoot = pathrs.OpenInRoot
36+
37+
// OpenatInRoot is a wrapper around [pathrs.OpenatInRoot].
38+
//
39+
// Deprecated: You should use [pathrs.OpenatInRoot] directly instead. This
40+
// wrapper will be removed in filepath-securejoin v0.6.
41+
OpenatInRoot = pathrs.OpenatInRoot
42+
43+
// Reopen is a wrapper around [pathrs.Reopen].
44+
//
45+
// Deprecated: You should use [pathrs.Reopen] directly instead. This
46+
// wrapper will be removed in filepath-securejoin v0.6.
47+
Reopen = pathrs.Reopen
48+
)

pathrs-lite/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## `pathrs-lite` ##
2+
3+
`github.com/cyphar/filepath-securejoin/pathrs-lite` provides a minimal **pure
4+
Go** implementation of the core bits of [libpathrs][]. This is not intended to
5+
be a complete replacement for libpathrs, instead it is mainly intended to be
6+
useful as a transition tool for existing Go projects.
7+
8+
The long-term plan for `pathrs-lite` is to provide a build tag that will cause
9+
all `pathrs-lite` operations to call into libpathrs directly, thus removing
10+
code duplication for projects that wish to make use of libpathrs (and providing
11+
the ability for software packagers to opt-in to libpathrs support without
12+
needing to patch upstream).
13+
14+
[libpathrs]: https://github.com/cyphar/libpathrs
15+
16+
### License ###
17+
18+
Most of this subpackage is licensed under the Mozilla Public License (version
19+
2.0). For more information, see the top-level [COPYING.md][] and
20+
[LICENSE.MPL-2.0][] files, as well as the individual license headers for each
21+
file.
22+
23+
```
24+
Copyright (C) 2024-2025 Aleksa Sarai <[email protected]>
25+
Copyright (C) 2024-2025 SUSE LLC
26+
27+
This Source Code Form is subject to the terms of the Mozilla Public
28+
License, v. 2.0. If a copy of the MPL was not distributed with this
29+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
30+
```
31+
32+
[COPYING.md]: ../COPYING.md
33+
[LICENSE.MPL-2.0]: ../LICENSE.MPL-2.0

pathrs-lite/doc.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
3+
//go:build linux
4+
5+
// Copyright (C) 2024-2025 Aleksa Sarai <[email protected]>
6+
// Copyright (C) 2024-2025 SUSE LLC
7+
//
8+
// This Source Code Form is subject to the terms of the Mozilla Public
9+
// License, v. 2.0. If a copy of the MPL was not distributed with this
10+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
11+
12+
// Package pathrs (pathrs-lite) is a less complete pure Go implementation of
13+
// some of the APIs provided by [libpathrs].
14+
package pathrs
File renamed without changes.

internal/assert/assert_test.go renamed to pathrs-lite/internal/assert/assert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
testassert "github.com/stretchr/testify/assert"
1717

18-
"github.com/cyphar/filepath-securejoin/internal/assert"
18+
"github.com/cyphar/filepath-securejoin/pathrs-lite/internal/assert"
1919
)
2020

2121
func TestAssertTrue(t *testing.T) {
File renamed without changes.

internal/fd/at_linux.go renamed to pathrs-lite/internal/fd/at_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
"golang.org/x/sys/unix"
2121

22-
"github.com/cyphar/filepath-securejoin/internal/gocompat"
22+
"github.com/cyphar/filepath-securejoin/pathrs-lite/internal/gocompat"
2323
)
2424

2525
// prepareAtWith returns -EBADF (an invalid fd) if dir is nil, otherwise using
File renamed without changes.

internal/fd/fd_linux.go renamed to pathrs-lite/internal/fd/fd_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
"golang.org/x/sys/unix"
2020

21-
"github.com/cyphar/filepath-securejoin/internal"
21+
"github.com/cyphar/filepath-securejoin/pathrs-lite/internal"
2222
)
2323

2424
// DupWithName creates a new file descriptor referencing the same underlying

0 commit comments

Comments
 (0)