Skip to content

Commit ea797f8

Browse files
authored
Merge pull request #1518 from LebedevRI/inrelease-signedby
`InRelease` file: support `Signed-By` field
2 parents 836d9f3 + a4cc921 commit ea797f8

25 files changed

+569
-5
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@ List of contributors, in chronological order:
7777
* Yaksh Bariya (https://github.com/thunder-coding)
7878
* Juan Calderon-Perez (https://github.com/gaby)
7979
* Ato Araki (https://github.com/atotto)
80+
* Roman Lebedev (https://github.com/LebedevRI)

api/publish.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ type publishedRepoCreateParams struct {
168168
SkipBz2 *bool ` json:"SkipBz2" example:"false"`
169169
// Provide index files by hash
170170
AcquireByHash *bool ` json:"AcquireByHash" example:"false"`
171+
// An optional field containing a comma separated list of OpenPGP key fingerprints to be used for validating the next Release file.
172+
SignedBy *string ` json:"SignedBy" example:""`
171173
// Enable multiple packages with the same filename in different distributions
172174
MultiDist *bool ` json:"MultiDist" example:"false"`
173175
}
@@ -341,6 +343,10 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
341343
published.AcquireByHash = *b.AcquireByHash
342344
}
343345

346+
if b.SignedBy != nil {
347+
published.SignedBy = *b.SignedBy
348+
}
349+
344350
duplicate := collection.CheckDuplicate(published)
345351
if duplicate != nil {
346352
_ = collectionFactory.PublishedRepoCollection().LoadComplete(duplicate, collectionFactory)
@@ -376,6 +382,8 @@ type publishedRepoUpdateSwitchParams struct {
376382
Snapshots []sourceParams ` json:"Snapshots"`
377383
// Provide index files by hash
378384
AcquireByHash *bool ` json:"AcquireByHash" example:"false"`
385+
// An optional field containing a comma separated list of OpenPGP key fingerprints to be used for validating the next Release file
386+
SignedBy *string ` json:"SignedBy" example:""`
379387
// Enable multiple packages with the same filename in different distributions
380388
MultiDist *bool ` json:"MultiDist" example:"false"`
381389
}
@@ -461,6 +469,10 @@ func apiPublishUpdateSwitch(c *gin.Context) {
461469
published.AcquireByHash = *b.AcquireByHash
462470
}
463471

472+
if b.SignedBy != nil {
473+
published.SignedBy = *b.SignedBy
474+
}
475+
464476
if b.MultiDist != nil {
465477
published.MultiDist = *b.MultiDist
466478
}
@@ -954,6 +966,8 @@ type publishedRepoUpdateParams struct {
954966
SkipCleanup *bool ` json:"SkipCleanup" example:"false"`
955967
// Provide index files by hash
956968
AcquireByHash *bool ` json:"AcquireByHash" example:"false"`
969+
// An optional field containing a comma separated list of OpenPGP key fingerprints to be used for validating the next Release file
970+
SignedBy *string ` json:"SignedBy" example:""`
957971
// Enable multiple packages with the same filename in different distributions
958972
MultiDist *bool ` json:"MultiDist" example:"false"`
959973
}
@@ -1020,6 +1034,10 @@ func apiPublishUpdate(c *gin.Context) {
10201034
published.AcquireByHash = *b.AcquireByHash
10211035
}
10221036

1037+
if b.SignedBy != nil {
1038+
published.SignedBy = *b.SignedBy
1039+
}
1040+
10231041
if b.MultiDist != nil {
10241042
published.MultiDist = *b.MultiDist
10251043
}

cmd/publish_repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Example:
5151
cmd.Flag.String("codename", "", "codename to publish (defaults to distribution)")
5252
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
5353
cmd.Flag.Bool("acquire-by-hash", false, "provide index files by hash")
54+
cmd.Flag.String("signed-by", "", "an optional field containing a comma separated list of OpenPGP key fingerprints to be used for validating the next Release file")
5455
cmd.Flag.Bool("multi-dist", false, "enable multiple packages with the same filename in different distributions")
5556

5657
return cmd

cmd/publish_snapshot.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error {
150150
published.AcquireByHash = context.Flags().Lookup("acquire-by-hash").Value.Get().(bool)
151151
}
152152

153+
if context.Flags().IsSet("signed-by") {
154+
published.SignedBy = context.Flags().Lookup("signed-by").Value.String()
155+
}
156+
153157
if context.Flags().IsSet("multi-dist") {
154158
published.MultiDist = context.Flags().Lookup("multi-dist").Value.Get().(bool)
155159
}
@@ -247,6 +251,7 @@ Example:
247251
cmd.Flag.String("codename", "", "codename to publish (defaults to distribution)")
248252
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
249253
cmd.Flag.Bool("acquire-by-hash", false, "provide index files by hash")
254+
cmd.Flag.String("signed-by", "", "an optional field containing a comma separated list of OpenPGP key fingerprints to be used for validating the next Release file")
250255
cmd.Flag.Bool("multi-dist", false, "enable multiple packages with the same filename in different distributions")
251256

252257
return cmd

cmd/publish_switch.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
9999
published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool)
100100
}
101101

102+
if context.Flags().IsSet("signed-by") {
103+
published.SignedBy = context.Flags().Lookup("signed-by").Value.String()
104+
}
105+
102106
if context.Flags().IsSet("multi-dist") {
103107
published.MultiDist = context.Flags().Lookup("multi-dist").Value.Get().(bool)
104108
}
@@ -162,6 +166,7 @@ This command would switch published repository (with one component) named ppa/wh
162166
cmd.Flag.Bool("skip-bz2", false, "don't generate bzipped indexes")
163167
cmd.Flag.String("component", "", "component names to update (for multi-component publishing, separate components with commas)")
164168
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
169+
cmd.Flag.String("signed-by", "", "an optional field containing a comma separated list of OpenPGP key fingerprints to be used for validating the next Release file")
165170
cmd.Flag.Bool("skip-cleanup", false, "don't remove unreferenced files in prefix/component")
166171
cmd.Flag.Bool("multi-dist", false, "enable multiple packages with the same filename in different distributions")
167172

cmd/publish_update.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func aptlyPublishUpdate(cmd *commander.Command, args []string) error {
6060
published.SkipBz2 = context.Flags().Lookup("skip-bz2").Value.Get().(bool)
6161
}
6262

63+
if context.Flags().IsSet("signed-by") {
64+
published.SignedBy = context.Flags().Lookup("signed-by").Value.String()
65+
}
66+
6367
if context.Flags().IsSet("multi-dist") {
6468
published.MultiDist = context.Flags().Lookup("multi-dist").Value.Get().(bool)
6569
}
@@ -125,6 +129,7 @@ Example:
125129
cmd.Flag.Bool("skip-contents", false, "don't generate Contents indexes")
126130
cmd.Flag.Bool("skip-bz2", false, "don't generate bzipped indexes")
127131
cmd.Flag.Bool("force-overwrite", false, "overwrite files in package pool in case of mismatch")
132+
cmd.Flag.String("signed-by", "", "an optional field containing a comma separated list of OpenPGP key fingerprints to be used for validating the next Release file")
128133
cmd.Flag.Bool("skip-cleanup", false, "don't remove unreferenced files in prefix/component")
129134
cmd.Flag.Bool("multi-dist", false, "enable multiple packages with the same filename in different distributions")
130135

deb/format.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ var (
2626
"Version",
2727
"Codename",
2828
"Date",
29+
"Valid-Until",
2930
"NotAutomatic",
3031
"ButAutomaticUpgrades",
32+
"Acquire-By-Hash",
33+
"Signed-By",
3134
"Architectures",
3235
"Architecture",
3336
"Components",

deb/publish.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ type PublishedRepo struct {
8181
// Provide index files per hash also
8282
AcquireByHash bool
8383

84+
// An optional field containing a comma separated list
85+
// of OpenPGP key fingerprints to be used
86+
// for validating the next Release file
87+
SignedBy string
88+
8489
// Support multiple distributions
8590
MultiDist bool
8691

@@ -529,6 +534,7 @@ func (p *PublishedRepo) MarshalJSON() ([]byte, error) {
529534
"Storage": p.Storage,
530535
"SkipContents": p.SkipContents,
531536
"AcquireByHash": p.AcquireByHash,
537+
"SignedBy": p.SignedBy,
532538
"MultiDist": p.MultiDist,
533539
})
534540
}
@@ -1070,6 +1076,9 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP
10701076
if p.AcquireByHash {
10711077
release["Acquire-By-Hash"] = "yes"
10721078
}
1079+
if p.SignedBy != "" {
1080+
release["Signed-By"] = p.SignedBy
1081+
}
10731082

10741083
var bufWriter *bufio.Writer
10751084
bufWriter, err = indexes.ReleaseIndex(component, arch, udeb).BufWriter()
@@ -1126,11 +1135,22 @@ func (p *PublishedRepo) Publish(packagePool aptly.PackagePool, publishedStorageP
11261135
release["Label"] = p.GetLabel()
11271136
release["Suite"] = p.GetSuite()
11281137
release["Codename"] = p.GetCodename()
1129-
release["Date"] = time.Now().UTC().Format("Mon, 2 Jan 2006 15:04:05 MST")
1138+
datetime_format := "Mon, 2 Jan 2006 15:04:05 MST"
1139+
date_now := time.Now().UTC()
1140+
release["Date"] = date_now.Format(datetime_format)
11301141
release["Architectures"] = strings.Join(utils.StrSlicesSubstract(p.Architectures, []string{ArchitectureSource}), " ")
11311142
if p.AcquireByHash {
11321143
release["Acquire-By-Hash"] = "yes"
11331144
}
1145+
if p.SignedBy != "" {
1146+
// "If the field is present, a client should only accept future updates
1147+
// to the repository that are signed with keys listed in the field.
1148+
// The field should be ignored if the Valid-Until field
1149+
// is not present or if it is expired."
1150+
release["Signed-By"] = p.SignedBy
1151+
// Let's use a century as a "forever" value.
1152+
release["Valid-Until"] = date_now.AddDate(100, 0, 0).Format(datetime_format)
1153+
}
11341154
release["Description"] = " Generated by aptly\n"
11351155
release["MD5Sum"] = ""
11361156
release["SHA1"] = ""

man/aptly.1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,10 @@ $ aptly publish repo testing
15651565
Options:
15661566
.
15671567
.TP
1568+
\-\fBsigned\-by\fR
1569+
set value for Signed-By field
1570+
.
1571+
.TP
15681572
\-\fBacquire\-by\-hash\fR
15691573
provide index files by hash
15701574
.
@@ -1706,6 +1710,10 @@ $ aptly publish snapshot wheezy\-main
17061710
Options:
17071711
.
17081712
.TP
1713+
\-\fBsigned\-by\fR
1714+
set value for Signed-By field
1715+
.
1716+
.TP
17091717
\-\fBacquire\-by\-hash\fR
17101718
provide index files by hash
17111719
.
@@ -2065,6 +2073,10 @@ This command would switch published repository (with one component) named ppa/wh
20652073
Options:
20662074
.
20672075
.TP
2076+
\-\fBsigned\-by\fR
2077+
set value for Signed-By field
2078+
.
2079+
.TP
20682080
\-\fBbatch\fR
20692081
run GPG with detached tty
20702082
.
@@ -2171,6 +2183,10 @@ $ aptly publish update wheezy ppa
21712183
Options:
21722184
.
21732185
.TP
2186+
\-\fBsigned\-by\fR
2187+
set value for Signed-By field
2188+
.
2189+
.TP
21742190
\-\fBbatch\fR
21752191
run GPG with detached tty
21762192
.

system/t06_publish/PublishList5Test_gold

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"Origin": "LP-PPA-gladky-anton-gnuplot",
1515
"Path": "./maverick",
1616
"Prefix": ".",
17+
"SignedBy": "",
1718
"SkipContents": false,
1819
"SourceKind": "snapshot",
1920
"Sources": [
@@ -39,6 +40,7 @@
3940
"Origin": "",
4041
"Path": "ppa/smira/wheezy",
4142
"Prefix": "ppa/smira",
43+
"SignedBy": "",
4244
"SkipContents": false,
4345
"SourceKind": "snapshot",
4446
"Sources": [
@@ -65,6 +67,7 @@
6567
"Origin": "origin1",
6668
"Path": "ppa/tr1/maverick",
6769
"Prefix": "ppa/tr1",
70+
"SignedBy": "",
6871
"SkipContents": false,
6972
"SourceKind": "snapshot",
7073
"Sources": [
@@ -91,6 +94,7 @@
9194
"Origin": "",
9295
"Path": "ppa/tr2/maverick",
9396
"Prefix": "ppa/tr2",
97+
"SignedBy": "",
9498
"SkipContents": false,
9599
"SourceKind": "snapshot",
96100
"Sources": [

0 commit comments

Comments
 (0)